为了账号安全,请及时绑定邮箱和手机立即绑定

对每行数据帧中的搜索词进行计数

对每行数据帧中的搜索词进行计数

海绵宝宝撒 2022-09-20 17:20:29
我有一个python中的数据帧word    string                                               count    wordSummaryapple    One apple price is 40apple    one apple price is 50 and three apples price are 60 but apple....我想从字符串中计算确切的单词,并在单词之前和之后的5chars中计算5charsword    string                                                         count  wordSummary apple    One apple price is 40                                            1   Once apple priceapple    one apple price is 50 and three apples price are 60 but apple    2  one apple price我尝试了以下部分,但显示错误。df["count"] = df["string"].count(df["word"])
查看完整描述

1 回答

?
慕桂英4014372

TA贡献1871条经验 获得超13个赞

尝试申请:

df['count'] = df.apply(lambda row: row['string'].lower().split(' ').count(row['word'].lower()), axis=1)

共享


查看完整回答
反对 回复 2022-09-20
  • 1 回答
  • 0 关注
  • 65 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号