pandas模块随堂笔记(2)

语法:

“”"

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 大黄,小黄

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值