How do I split a string into several columns in a dataframe with pandas Python?

前端 未结 2 1241
南方客
南方客 2020-12-09 12:42

I am aware of the following questions:

1.) How to split a column based on several string indices using pandas? 2.) How do I split text in a column into multiple rows

2条回答
  •  不思量自难忘°
    2020-12-09 13:28

    Slightly less concise than the expand option, but here is an alternative way:

    In [29]: cols = ['string_1', 'string_2', 'string_3']   
    
    In [30]: pandas.DataFrame(df.string.str.split(', ').tolist(), columns=cols)
    Out[30]: 
      string_1 string_2 string_3
    0  astring      isa   string
    1  another   string       la
    2      123      232  another
    

提交回复
热议问题