I have a pandas column that contains strings. I want to get a word count of all of the words in the entire column. What\'s the best way of doing that without looping through eac
You could use the vectorized string operations:
In [7]: df["a"].str.split().str.len().sum()
Out[7]: 6
which comes from
In [8]: df["a"].str.split()
Out[8]:
0 [some, words]
1 [lots, more, words]
2 [hi]
Name: a, dtype: object
In [9]: df["a"].str.split().str.len()
Out[9]:
0 2
1 3
2 1
Name: a, dtype: int64
In [10]: df["a"].str.split().str.len().sum()
Out[10]: 6