2017-02-08 82 views
0

我有以下代碼:大熊貓:時間戳轉換類型錯誤

import datatime as dt 

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

其中row是熊貓數據幀的行。

但得到了下面的輸出和錯誤:

<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

fromtimestamp預計以秒爲單位的歷元時間爲整數。 pandas已經有方法.date輸出datetime.date類型。

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