我有一个数据帧与2列 - 一些值和时间。时间戳是时代格式,我试图使用python中的时间库中的strftime函数进行转换。将时期转换为日期时间格式python - typeerror
下面是一些样本数据
df = [{'A': 762, 'Time': 1512255906},
{'A': 810, 'Time': 1480719906}]
注:时间为纪元格式。在执行日期转换的strftime函数之前,我正在执行一些转换以确保其类型为numeric(float)。
下面的代码:
df['Time'] = pd.to_numeric(df['Time'], errors='coerce').fillna(0)
df['Time'].dtype
我收到一个错误使用时,在这条线
df['Time'] = time.strftime("%d-%m", time.localtime(df['Time']))
回溯:
TypeError Traceback (most recent call last)
<ipython-input-53-86f4db0b80e4> in <module>()
----> 1 df['Time'] = time.strftime("%d-%m", time.localtime(df['Time']))
TypeError: cannot convert the series to <class 'int'>
[你应该考虑接受一个答案(https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) –
我接受他们。谢谢。 – keval
如果您仔细阅读链接页面,它会解释您只能接受一个。 –