为什么使用sort_values对时间戳进行排序不起作用?

问题描述 投票:0回答:1

我有一列时间戳转换为人类可读的形式。我试图从epochtime和转换后对它进行排序。它给了我

Fri, 08 Feb 2019 17:24:16 IST
Mon, 11 Feb 2019 02:19:40 IST
Sat, 09 Feb 2019 00:22:43 IST

哪个没有排序。

我用过sort_values()

each_tracker_df = each_tracker_df.sort_values(["timestamp"],ascending=True)

为什么不工作?

python-3.x sorting datetime timestamp epoch
1个回答
0
投票

因为所有时间都在IST。用NULL替换字符串IST。

>>import datetime
>>times=['Fri, 10 Feb 2010 17:24:16','Fri, 11 Feb 2010 17:24:16','Fri, 11 Feb 2019 17:24:16']
>>change_format=[]
>> for time in times:
         change_format.append(datetime.datetime.strptime(time, '%a, %d %b %Y %H:%M:%S'))
>>change_format.sort()
© www.soinside.com 2019 - 2024. All rights reserved.