熊猫:将时间戳列转换为Unix纪元

时间:2020-04-21 12:22:37

标签: python pandas

我有一个数据框df,其中包含要转换为Unix纪元的时间戳列。

这就是我在做什么

tmp = df[['timestamp']]
tmp['timestamp'] = pd.to_datetime(tmp['timestamp'])
tmp['date'] =  (tmp['timestamp'] - datetime.datetime(1970,1,1))
tmp.head()

    timestamp           date
0   2020-03-21 13:10:01 18342 days 13:10:01
1   2020-03-21 13:10:03 18342 days 13:10:03
2   2020-03-21 13:10:13 18342 days 13:10:13
3   2020-03-21 13:10:48 18342 days 13:10:48
4   2020-03-21 13:11:28 18342 days 13:11:28

现在我尝试提取出现错误的总秒数

tmp['unix'] = tmp['date'].datetime.total_seconds()
AttributeError: 'Series' object has no attribute 'datetime'

0 个答案:

没有答案