I created a data frame by importing a csv file. And converted the date column to datetime and made it an index. However, when sorting the index, it does not give the result that I need
print(df.head())
df['Date'] = pd.to_datetime(df['Date'])
df.index = df['Date']
del df['Date']
df.sort_index()
print(df.head())
Here is the result:
Date Last
0 2016-12-30 1.05550
1 2016-12-29 1.05275
2 2016-12-28 1.04610
3 2016-12-27 1.05015
4 2016-12-23 1.05005
Last
Date
2016-12-30 1.05550
2016-12-29 1.05275
2016-12-28 1.04610
2016-12-27 1.05015
2016-12-23 1.05005
The date actually returns to 1999, so if I sort it by date, should it show the data in ascending order?
source
share