Pandas add new columns based on splitting another column

前端 未结 3 1809
失恋的感觉
失恋的感觉 2021-01-03 04:42

I have a pandas dataframe like the following:

A              B
US,65,AMAZON   2016
US,65,EBAY     2016

My goal is to get to look like this:

3条回答
  •  -上瘾入骨i
    2021-01-03 05:26

    This will not give the output as expected it will only give the df['A'] first value which is 'U'

    This is okay to create column based on provided data df1=pd.DataFrame([x.split(',') for x in df['A'].tolist()],columns= ['country','code','com'])

    instead of for lambda also can be use

提交回复
热议问题