Split a dataframe column's list into two dataframe columns

前端 未结 2 1500
迷失自我
迷失自我 2021-01-14 16:20

I\'m effectively trying to do a text-to-columns (from MS Excel) action, but in Pandas.

I have a dataframe that contains values like: 1_1, 2_1, 3_1, and I only want t

2条回答
  •  独厮守ぢ
    2021-01-14 16:56

    Use expand=True when doing the split to get multiple columns:

    test['values'].str.split('_', expand=True)
    

    If there's only one underscore, and you only care about the value to the right, you could use:

    test['values'].str.split('_').str[1]
    

提交回复
热议问题