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?

1

1 Answer 1

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.