语法:
“”"
lower() | 将Series/Index中的字符串转换为小写 |
---|---|
upper() | 将Series/Index中的字符串转换为大写 |
len() | 计算字符串长度 |
strip() | 帮助从两侧的系列/索引中的每个字符串中删除空格(包括换行符) |
split(’ ') | 用给定的模式拆分每个字符串 |
cat(sep=’ ') | 使用给定的分隔符连接系列/索引元素 |
get_dummies() | 返回具有单热编码值的数据帧(DataFrame) |
contains(pattern) | 如果元素中包含子字符串,则返回每个元素的布尔值True,否则为False |
replace(a,b) | 将值a替换为值b |
repeat(value) | 重复每个元素指定的次数 |
count(pattern) | 返回模式中每个元素的出现总数 |
startswith(pattern) | 如果系列/索引中的元素以模式开始,则返回true |
endswith(pattern) | 如果系列/索引中的元素以模式结束,则返回true |
find(pattern) | 返回模式第一次出现的位置 |
findall(pattern) | 返回模式的所有出现的列表 |
swapcase() | 变换字母大小写 |
islower() | 检查系列/索引中每个字符串中的所有字符是否小写,返回布尔值 |
isupper() | 检查系列/索引中每个字符串中的所有字符是否大写,返回布尔值 |
isnumeric() | 检查系列/索引中每个字符串中的所有字符是否为数字,返回布尔值 |
“”"
s3=pd.Series([‘大黄,小黄’,‘狗蛋 ‘,’ 铁蛋’,’ 富贵’],index=[‘row1’,‘row2’,‘row3’,‘row4’])
s4=pd.Series([10,10,10,np.NaN],index=[‘row1’,‘row2’,‘row3’,‘row4’])
x1={
‘name’:s3,
‘age’:s4
}
df2=pd.DataFrame(x1)
#print(df2)
count(value)
#print(’—count(value)—’)
#df_name=df2[‘name’]
#print(df_name.str.count(‘黄’))
“”"
—count(value)—
row1 2
row2 0
row3 0
row4 0
Name: name, dtype: int64
“”"
repeat(n)
#print(’----repeat(n)—’)
#df_name=df2[‘name’]
#print(df_name.str.repeat(3))
“”"
----repeat(n)—
row1 大黄,小黄大黄,小黄大黄,小黄
row2 狗蛋 狗蛋 狗蛋
row3 铁蛋 铁蛋 铁蛋
row4 富贵 富贵 富贵
Name: name, dtype: object
“”"
replace()—替换
#print(’—replace()—替换–’)
#df_name=df2[‘name’]
#print(df_name.str.replace(‘富贵’,‘栓柱’))
“”"
—replace()—替换–
row1 大黄,小黄