How to save split data in panda in reverse order?

前端 未结 2 1902
耶瑟儿~
耶瑟儿~ 2021-01-24 10:52

You can use this to create the dataframe:

xyz = pd.DataFrame({\'release\' : [\'7 June 2013\', \'2012\', \'31 January 2013\',
                                 \'F         


        
相关标签:
2条回答
  • 2021-01-24 11:32

    Try reversing the result.

    dataframe[['year','month','day']] = dataframe['release'].str.rsplit(expand=True).reverse()
    
    0 讨论(0)
  • 2021-01-24 11:37

    You could

    In [17]: dataframe[['year', 'month', 'day']] = dataframe['release'].apply(
                                                        lambda x: pd.Series(x.split()[::-1]))
    In [18]: dataframe
    Out[18]:
               release  year     month  day
    0      7 June 2013  2013      June    7
    1             2012  2012       NaN  NaN
    2  31 January 2013  2013   January   31
    3    February 2008  2008  February  NaN
    4     17 June 2014  2014      June   17
    5             2013  2013       NaN  NaN
    
    0 讨论(0)
提交回复
热议问题