title: TypeError: object of type 'float' has no len() & TypeError: 'float' object is not iterable
body: <p>I have a dataset imported as DataFrame "new_data_words". There is a column "page_name" containing messy webpage names, like "<code>%D8%AA%D8%B5%D9%86%D9%8A%D9%81:%D8%A2%D9%84%D9...</code>", "<code>%D9%85%D9%84%D9%81:IT-Airforce-OR2.png</code>" or simply "<code>1950</code>". I want to create a new column 'word_count' to have the count of words in the page name (words are delimited by '_')</p>
  
  <p>Here are my codes:</p>
  
  <p>To split to words:</p>
  
  <pre><code>b = list(new_data_words['page_name'].str.split('_'))
  new_data_words['words'] = b
  </code></pre>
  
  <p>I checked the type of b is <strong>list</strong> type and len(b) is <strong>6035980</strong>.
  One sample value:</p>
  
  <pre><code>In [1]: new_data_words.loc[0,'words']
  Out[2]: ['%D8%AA%D8%B5%D9%86%D9%8A%D9%81:%D8%A2%D9%84%D9%87%D8%A9',
           '%D8%A8%D9%84%D8%A7%D8%AF',
           '%D8%A7%D9%84%D8%B1%D8%A7%D9%81%D8%AF%D9%8A%D9%86']
  </code></pre>
  
  <p>I created another column "word_count" to count the elements of the list in each row of column "words". (Have to use loop to touch the elements of list in each row)</p>
  
  <p>But I had errors:</p>
  
  <pre><code>x = []
  i = []
  c = 0
  for i in b:    # i is list type, with elements are string, I checked
      c=c+1
      x.append(len(i))
  
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-12-c0cf0cfbc458&gt; in &lt;module&gt;()
        6         #y = str(y)
        7     c=c+1
  ----&gt; 8     x.append(len(i))
  
  TypeError: object of type 'float' has no len()
  </code></pre>
  
  <p>I don't know why it is float type.....</p>
  
  <p>However if I only add a print, it worked</p>
  
  <pre><code>x = []
  i = []
  c = 0
  for i in b:
      c=c+1
      print len(i)
      x.append(len(i))
  
  3
  2
  3
  2
  3
  1
  8
  ...
  </code></pre>
  
  <p>But c = len(x) = 68516, much smaller than 6 millions.</p>
  
  <p>I tried to force the elements to be string again, another error happened:</p>
  
  <pre><code>x = []
  for i in b:
      for y in i:
          y = str(y)
      x.append(len(i))
  
  
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-164-c86f5f48b80c&gt; in &lt;module&gt;()
        1 x = []
        2 for i in b:
  ----&gt; 3     for y in i:
        4         y = str(y)
        5     x.append(len(i))
  TypeError: 'float' object is not iterable
  </code></pre>
  
  <p>I think i is list type and is iterable...</p>
  
  <p>Again, if I did not append, but only print, it worked:</p>
  
  <pre><code>x = []
  for i in b:
      for y in i:
          y = str(y)
      print (len(i))
  </code></pre>
  
  <hr>
  
  <p>Another example:
  This works:</p>
  
  <pre><code>a = []
  for i in range(10000):
      a.append(len(new_data_words.loc[i,"words"]))
  </code></pre>
  
  <p>Changed to a dynamic range, it does not work:</p>
  
  <pre><code>a = []
  for i in range(len(b)):
      a.append(len(new_data_words.loc[i,"words"]))
  
  
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-20-f9d0af3c448f&gt; in &lt;module&gt;()
        1 a = []
        2 for i in range(len(b)):
  ----&gt; 3     a.append(len(new_data_words.loc[i,"words"]))
  
  TypeError: object of type 'float' has no len()
  </code></pre>
  
  <p>This does not work either......</p>
  
  <pre><code>a = []
  for i in range(6035980):
      a.append(len(new_data_words.loc[i,"words"]))
  </code></pre>
  
  <p>Seems like there are some abnormal in the list. But I don't know what that is or how to find it.</p>
  
  <p>Anyone can help please?</p>