I'm trying to create a new column in a DataFrame that contains the word count for the respective row. I'm looking for the total number of words, not frequencies of each distinct word. I assumed there would be a simple/quick way to do this common task, but after googling around and reading a handful of SO posts (1, 2, 3, 4) I'm stuck. I've tried the solutions put forward in the linked SO posts, but got lots of attribute errors back.
words = df['col'].split()
df['totalwords'] = len(words)
results in
AttributeError: 'Series' object has no attribute 'split'
and
f = lambda x: len(x["col"].split()) -1
df['totalwords'] = df.apply(f, axis=1)
results in
AttributeError: ("'list' object has no attribute 'split'", 'occurred at index 0')