【发布时间】:2021-02-17 01:29:57
【问题描述】:
这是我的数据
id enter_time
1 1.481044e+12
2 1.486d74e+12
这是我的预期输出
id enter_time enter_timestamp
1 1.481044e+12 2017-07-14 08:10:03
2 1.486774e+12 2017-07-15 08:10:00
注意:上面预期的“enter_timestamp”中的值是假的,它只是为了给出预期格式的想法,下面是额外的信息,以防需要回答
In : main['enter_time'].dtype
Out: dtype('float64')
我已经尝试过的
import datetime
main['loan_timestamp'] = datetime.datetime.fromtimestamp(main['loan_time'])
和输出
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-27-cfe2d514debb> in <module>
1 import datetime
----> 2 main['loan_timestamp'] = datetime.datetime.fromtimestamp(main['loan_time'])
/opt/conda/lib/python3.8/site-packages/pandas/core/series.py in wrapper(self)
127 if len(self) == 1:
128 return converter(self.iloc[0])
--> 129 raise TypeError(f"cannot convert the series to {converter}")
130
131 wrapper.__name__ = f"__{converter.__name__}__"
TypeError: cannot convert the series to <class 'int'>
【问题讨论】:
-
是的@MrFuppes,它在 [25] 中回答,但我不知道它来自 unix 时间之前
-
没问题,我只是加了链接,方便其他人来这里轻松找到相关资源。
标签: python pandas dataframe timestamp