Count Appearances Of A String Throughout Columns In Pandas
Consider the following dataframe: import pandas as pd df = pd.DataFrame(['What is the answer', 'the answer isn't here, but the answer is 42' ,
Solution 1:
You need str.count
In [5285]: df.words.str.count("the answer").sum()
Out[5285]: 3
In [5286]: df.words.str.count("the answer")
Out[5286]:
0 1
1 2
2 0
3 0
Name: words, dtype: int64
Post a Comment for "Count Appearances Of A String Throughout Columns In Pandas"