Accessing every 1st element of Pandas DataFrame column containing lists

后端 未结 4 1388
青春惊慌失措
青春惊慌失措 2020-11-27 06:56

I have a Pandas DataFrame with a column containing lists objects

      A
0   [1,2]
1   [3,4]
2   [8,9] 
3   [2,6]

How can I access the firs

4条回答
  •  [愿得一人]
    2020-11-27 08:02

    You can use map and a lambda function

    df.loc[:, 'new_col'] = df.A.map(lambda x: x[0])
    

提交回复
热议问题