pandas:timestamp conversion类型错误

时间:2017-02-08 20:38:36

标签: python-3.x pandas datetime timestamp

我有以下代码:

import datatime as dt

print(type(row['my_timestamp']))
current_date = dt.date.fromtimestamp(row['my_timestamp'])

其中row是pandas数据框行。

但得到以下输出和错误:

<class 'pandas.tslib.Timestamp'>
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-44-95348c1ae55f> in <module>()
     10     print(type(row['my_timestamp']))
---> 11     current_date = dt.date.fromtimestamp(row['my_timestamp'])

TypeError: an integer is required (got type Timestamp)

知道我可能错过了什么吗?谢谢!

1 个答案:

答案 0 :(得分:1)

fromtimestamp期望以秒为单位的纪元时间为整数。 pandas已经有方法.date输出datetime.date类型。

current_date = row['my_timestamp'].date()