Pandas sort data by date

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?

+4
source share
1 answer

MaxU: , , pandas, "" dataframe, . MaxU, ( "" ), :

df = df.sort_index()

inplace=True, .

df.sort_index(inplace=True)

, , " ", . , inplace. sytle, ...

+1
source

Source: https://habr.com/ru/post/1665559/


All Articles