I have a dataframe with columns consisting of lists of numbers:
idx codes new_column
0 [12,18,5]
1 [22,15]
2 [4]
3 [15,1]
How can I add a new column to the dataframe consisting of the first list entry of the codes column:
idx codes new_column
0 [12,18,5] 12
1 [22,15] 22
2 [4] 4
3 [15,1] 15
I tried:
df['new_column']=df['codes'][0]
However, that didn't work.