0

I currently have a dataframe that contains a list of floats within a column, and I want to add a second column to the df that counts the length of the list within the first column (the number of items within that list). What would be the easiest way to go about doing this and would I have to write a function that iterates over each item in the column?

LDH
  • 1
  • 1
  • 1
  • IIUC correctly, the first thing might be to consider how to set up your DF so that columns do not contain python lists of values. They become difficult to work with an stop you using most of the fast features of pandas – roganjosh Feb 19 '18 at 20:46

1 Answers1

2

This should work:

df['list_len'] = df['list_column'].str.len()
joaoavf
  • 1,343
  • 1
  • 12
  • 25