title: Count number of words per row
body: <p>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 (<a href="https://stackoverflow.com/questions/13970203/how-to-count-average-sentence-length-in-words-from-a-text-file-contains-100-se">1</a>, <a href="https://stackoverflow.com/questions/36108377/how-to-use-the-split-function-on-every-row-in-a-dataframe-in-python">2</a>, <a href="https://stackoverflow.com/questions/9288169/python-word-length-function-example-needed">3</a>, <a href="https://stackoverflow.com/questions/10677020/real-word-count-in-nltk#10677060">4</a>) I'm stuck. I've tried the solutions put forward in the linked SO posts, but got lots of attribute errors back.</p>
  <pre><code>words = df['col'].split()
  df['totalwords'] = len(words)
  </code></pre>
  <p>results in</p>
  <pre><code>AttributeError: 'Series' object has no attribute 'split'
  </code></pre>
  <p>and</p>
  <pre><code>f = lambda x: len(x[&quot;col&quot;].split()) -1
  df['totalwords'] = df.apply(f, axis=1)
  </code></pre>
  <p>results in</p>
  <pre><code>AttributeError: (&quot;'list' object has no attribute 'split'&quot;, 'occurred at index 0')
  </code></pre>