请看下面的数据帧:
import pandas as pd
df = pd.DataFrame(["What is the answer",
"the answer isn't here, but the answer is 42" ,
"dogs are nice",
"How are you"], columns=['words'])
df
words
0 What is the answer
1 the answer isn't here, but the answer is 42
2 dogs are nice
3 How are you
我想指望某些字符串的出现次数,可以在每个索引重复几次。
例如,我想算的次数the answer
出现。 我试过了:
df.words.str.contains(r'the answer').count()
我希望有一个解决方案,但输出为4
。 我不明白为什么。 the answer
出现3次。
What is **the answer**
**the answer** isn't here, but **the answer** is 42
注:搜索字符串可能会出现一次以上的行