gpt4 book ai didi

python - Pandas :时间戳到日期时间

转载 作者:太空狗 更新时间:2023-10-29 20:16:37 24 4
gpt4 key购买 nike

我有数据框和带有日期的列

 date
1476329529
1476329530
1476329803
1476329805
1476329805
1476329805

我使用 df['date'] = pd.to_datetime(df.date, format='%Y-%m-%d %H:%M:%S')转换它,但我得到了奇怪的结果

 date 
1970-01-01 00:00:01.476329529
1970-01-01 00:00:01.476329530
1970-01-01 00:00:01.476329803
1970-01-01 00:00:01.476329805
1970-01-01 00:00:01.476329805
1970-01-01 00:00:01.476329805

也许我做错了什么

最佳答案

这看起来像是纪元时间戳,它是自 1970 年 1 月 1 日以来的秒数:

In [71]:
pd.to_datetime(df['date'], unit='s')

Out[71]:
0 2016-10-13 03:32:09
1 2016-10-13 03:32:10
2 2016-10-13 03:36:43
3 2016-10-13 03:36:45
4 2016-10-13 03:36:45
5 2016-10-13 03:36:45
Name: date, dtype: datetime64[ns]

关于python - Pandas :时间戳到日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40038169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com