I have the following dataframe -
ID | Column1 |
0 | [] |
1 | [1,2] |
2 | [] |
I want a column which gives the length of the list in column1. Result should look like -
ID | Column1 | Column2 |
0 | [] | 0 |
1 | [1,2] | 2 |
2 | [] | 0 |
I tried using lambda function but it is not giving the number of rows in the data frame as every entry in column 2 -
df1 = df.assign(Column2 = lambda x: (len(x['Column1'])))
Can someone please help me out here?