比如我的dataframe里有一列time
'2017-01-21 18:00:00', '2017-01-21 09:00:00','2017-01-21 15:00:00', '2017-01-21 12:00:00', '2017-01-21 13:00:00', '2017-01-21 14:00:00'
怎么让我的dataframe按照time时间先后顺序排列?
1个回答
先把它转为时间对象
df['time'] = pd.to_datetime(df['time'])
然后再对time这列排序
df.sort_values('time', inplace=True)