title: Counting elements of an array in a new column of a data frame row by row
body: <p>I didn't find a solution in the forum that helped me.
  I have a very big data frame of transportation data. One of my 33 columns of my data frame is an array which includes the allowed labels of the solution (of this row).</p>
  <p>So the column is:</p>
  <pre><code>usedLabels
  
  [db_fv, blablacar, flixbus]
  
  [db_fv, blablacar, flixbus]
  
  [db_fv, blablacar, flixbus, airplane]
  
  [db_fv, blablacar]
  </code></pre>
  <p>and I want to add a column that counts the entry of each array per row:</p>
  <pre><code>usedLabelsCount
  
  3
  
  3
  
  4
  
  2
  </code></pre>
  <p>This is what I tried so far:</p>
  <pre><code>size = 1
  for dim in df['usedLabels']: size *= dim
      
  df['usedLabelsCount'] = df.set_index(['usedLabels']).count(level=&quot;usedLabels&quot;)
  df['usedLabelsCount'] = len(df['usedLabels'])
  
  df['usedLabelsCount'] = df['usedLabels'].count
  </code></pre>
  <p>my results with <code>.count</code> is:</p>
  <pre><code>&lt;bound method Series.count of 0 [db_fv...&gt;
  </code></pre>
  <p>and with <code>len</code> I get the count of all rows (and not for each row). So each row of usedLabelsCount would contain 903829 (which is the overall count and not per row)</p>
  <p>Thank you!</p>
  <p>Edit:
  The suggested solution (see below) didn't quite work:</p>
  <pre><code>df['UsedLabelsCount']=[len(i) for i in df['usedLabels']]
  </code></pre>
  <p>I tried it, but now it counts 27. Which is the overall unique value of the labels (and not per row). I don't know why.. I tried this too:</p>
  <pre><code>for index, row in df.iterrows(): a = (len(i) for i in df['usedLabels']) df['usedLabelsCount']= a 
  </code></pre>
  <p>but this prints that error into the data frame (the codes runs): <code>&lt;generator object &lt;genexpr&gt; at 0x7f9566666c80&gt;</code>
  any ideas?</p>
  <p>Edit 2:
  so this is some sample data:</p>
  <blockquote>
  <p><a href="https://github.com/Hektor1997/sample-data.git" rel="nofollow noreferrer">https://github.com/Hektor1997/sample-data.git</a></p>
  </blockquote>