Answers for "dataframe string find count"

0

dataframe string find count

In [21]: df = pd.DataFrame(['hello', 'world', 'hehe'], columns=['words'])

In [22]: df.words.str.count("he|wo")
Out[22]:
0    1
1    1
2    2
Name: words, dtype: int64

In [23]: df.words.str.count("he|wo").sum()
Out[23]: 4
Posted by: Guest on August-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language