ascending=False
will sort from newest to oldest, but you are asking to sort oldest to newest, so you don't need that option;
- there is a
key
option to specify how to parse the values before sorting them;
- you may or may not want option
ignore_index=True
, which I included below.
We can use the key
option to parse the values into datetime
objects with pandas.to_datetime
.
import pandas as pd
df = pd.DataFrame({'Date': ['Apr 2022', 'Dec 2021', 'May 2022', 'May 2021'], 'Price': [2, 8, 12, 15]})
df = df.sort_values(by='Date', ignore_index=True, key=pd.to_datetime)
print(df)
# Date Price
# 0 May 2021 15
# 1 Dec 2021 8
# 2 Apr 2022 2
# 3 May 2022 12
Relevant documentation: