I have .csv data that I want to sort by it's date column. My date format is of the following:
Week,Quarter,Year: So WK01Q12001 for example.
When I .sort() my dataframe on this column, the resulting is sorted like:
WK01Q12001, WK01Q12002, WK01Q12003, WK01Q22001, WK01Q22002, WK01Q22003, ... WK02Q12001, WK02Q12002...
for example. This makes sense because its sorting the string in ascending order.
But I need my data sorted chronologically such that the result is like the following:
WK01Q12001, WK02Q12001, WK03Q12001, WK04Q12001, ... , WK01Q22001, WK02Q22001, ... WK01Q12002, WK02Q22002 ...
How can I sort it this way using pandas? Perhaps sorting the string in reverse? (right to left) or creating some kind of datetime object?
I have also tried using Series(): pd.Series([pd.to_datetime(d) for d in weeklyData['Date']])
But the result is same as the above .sort() method.
UPDATE: My DataFrame is similar in format to an excel sheet and currently looks like the following. I want to sort chronologically by 'Date'.
Date Price Volume
WK01Q12001 32 500
WK01Q12002 43 400
WK01Q12003 55 300
WK01Q12004 58 350
WK01Q22001 33 480
WK01Q22002 40 450
.
.
.
WK13Q42004 60 400