pandas :时间戳记到日期时间 [英] Pandas: timestamp to datetime
本文介绍了 pandas :时间戳记到日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有数据框和带有日期的列,看起来像
I have dataframe and column with dates looks like
date
1476329529
1476329530
1476329803
1476329805
1476329805
1476329805
我使用df['date'] = pd.to_datetime(df.date, format='%Y-%m-%d %H:%M:%S')
进行转换,但结果很奇怪
I use df['date'] = pd.to_datetime(df.date, format='%Y-%m-%d %H:%M:%S')
to convert that, but I'm get strange result
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日以来的秒数:
This looks look epoch timestamps which is number of seconds since 1st January 1970 :
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]
这篇关于 pandas :时间戳记到日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文