0

I have a column called 'SubmitTime' which is a string per observation. An example would be: 'Wed Apr 12 14:42:23 PDT 2017'

I need to sort this dataframe based on submission time (the ones that submitted first, are on top). How can I convert this column into datetime and sort the dataframe in Pandas?

amaatouq
  • 2,297
  • 5
  • 29
  • 50
  • Possible duplicate of [Convert Pandas Column to DateTime](http://stackoverflow.com/questions/26763344/convert-pandas-column-to-datetime) – tmrlvi Apr 14 '17 at 08:09

1 Answers1

1

Assuming you dataframe is df

df.iloc[pd.to_datetime(df.SubmitTime).argsort()]

This leaves your dataframe intact, 'SubmitTime' remains strings

Otherwise, I'd convert 'SubmitTime' to datetime and sort

df.assign(SubmitTime=pd.to_datetime(df.SubmitTime)).sort_values('SubmitTime')
piRSquared
  • 285,575
  • 57
  • 475
  • 624