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

我有一个python中的数据帧


word    string                                               count    wordSummary

apple    One apple price is 40

apple    one apple price is 50 and three apples price are 60 but apple....


我想从字符串中计算确切的单词,并在单词之前和之后的5chars中计算5chars


word    string                                                         count  wordSummary 

apple    One apple price is 40                                            1   Once apple price

apple    one apple price is 50 and three apples price are 60 but apple    2  one apple price


我尝试了以下部分,但显示错误。


df["count"] = df["string"].count(df["word"])


海绵宝宝撒
浏览 66回答 1
1回答

慕桂英4014372

尝试申请:df['count'] = df.apply(lambda row: row['string'].lower().split(' ').count(row['word'].lower()), axis=1)共享
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java