J Doe
J Doe

Reputation: 359

Pandas TimeStamps

I have a data that looks like

Column A (timestamp)           Column B (Price)       Column  C(Volume)

20140804:10:00:13.281486,782.83,443355
20140804:10:00:13.400113,955.71,348603
20140804:10:00:13.555512,1206.38,467175
20140804:10:00:13.435677,1033.50,230056

I am trying to sort by timestamps and using the following code:

sorted_time = pd.to_datetime(df.time, format="%Y%m%d:%H:%M:%S.%f").sort_values()

All I am getting is the column for times. Any help will be appreciated.

Upvotes: 0

Views: 340

Answers (1)

akuiper
akuiper

Reputation: 215127

You need to call sort_values on the data frame, where you can specify time as the sort by column:

df.time = pd.to_datetime(df.time, format="%Y%m%d:%H:%M:%S.%f")
df = df.sort_values(by = 'time')

Upvotes: 1

Related Questions