我尝试使用
df.sort_values(by='date')
按日期对下面显示的数据框进行排序,但它不起作用。有什么想法可以确保正确排序吗? symbol date open close high low
0 GOOG 2007-01-03 232.77 233.56 238.09 230.32
1 GOOG 2007-01-05 241.01 243.35 243.51 238.82
2 GOOG 2007-01-04 234.27 241.39 241.73 233.94
...
2692 GOOG 2017-11-30 1022.37 1021.41 1028.49 1015.00
2693 GOOG 2017-11-29 1042.68 1021.66 1044.08 1015.65
2694 GOOG 2017-12-01 1015.80 1010.17 1022.49 1002.02
df.sort_values(by='date')
不起作用。我不知道为什么。 - user7304253df.sort_values
”,但显然,“不起作用”,那么它为什么不起作用呢?提供一个最小可复现示例[mcve]。 - juanpa.arrivillagadf.sort_values(by='date')
returns sorted DF, but it doesn't sort in place. So either use:df = df.sort_values(by='date')
ordf.sort_values(by='date', inplace=True)
- MaxU - stand with Ukrainedf = df.sort_values(by='date')
是有效的。如果您回答的话,我会接受它。 - user7304253