Python 如何解决TypeError:无法将序列转换为

Python 如何解决TypeError:无法将序列转换为,python,pandas,epoch,Python,Pandas,Epoch,对于特定的历元值,时间的历元值转换如下: time.strftime("%H:%M:%S ", time.localtime(28000000000)) Out[82]: '07:16:40 ' 但当我将上述方法应用于数据集中的历元时间列时 time.strftime("%H:%M:%S ", time.localtime(df1['d'])) 我遇到以下错误: TypeError: cannot convert the series to type 'float' 我错在哪

对于特定的历元值,时间的历元值转换如下:

time.strftime("%H:%M:%S ", time.localtime(28000000000))  
Out[82]: '07:16:40 '     
但当我将上述方法应用于数据集中的历元时间列时

time.strftime("%H:%M:%S ", time.localtime(df1['d']))
我遇到以下错误:

TypeError: cannot convert the series to type 'float'
我错在哪里

df1['d']是历元持续时间,列中的数据如下:

28000000000
16000000000
33000000000
28000000000
27000000000
22000000000
26000000000
22000000000
22000000000
22000000000
46000000000
我需要的是纪元时间而不是日期时间对象格式

我认为需要使用lambda函数:

df1 = pd.DataFrame({'d':[28000000000,28000000000]})

df1['times'] = df1['d'].apply(lambda x: time.strftime("%H:%M:%S", time.localtime(x)))
或列表理解:

你可以使用地图功能

import pandas as pd
import time

df = pd.DataFrame([[28000000000, 2.5], [28100000000, 2.54]], columns=['d', 'e'])

df['time'] = df.d.map(lambda t: time.strftime("%H:%M:%S ", time.localtime(t)))
print(df)
#              d     e       time
# 0  28000000000  2.50  03:46:40 
# 1  28100000000  2.54  13:33:20 

时间的值是什么。localtimedf1['d']?Hello@sacindobey时间值。localtimedf1['d']给出类型错误:无法将序列转换为抱歉我是指df1['d']?df1['d']在诸如2800000001600000003300000002800000002700000002200000000260000000022000000002200000000220000000022000000002200000000220000000046000000000这样的列中有历元时间持续时间。我将在主要部分添加这些值。可能重复的是,上述两种方法都有效。谢谢一个疑问是,如果需要多个列以这种方式进行转换,是否可能?是的,这是可能的,cols=['d','d1','d2'],然后df1[cols]=df1[cols]。applymaplambda x:time.strftime%H:%M:%S,time.localtimex
import pandas as pd
import time

df = pd.DataFrame([[28000000000, 2.5], [28100000000, 2.54]], columns=['d', 'e'])

df['time'] = df.d.map(lambda t: time.strftime("%H:%M:%S ", time.localtime(t)))
print(df)
#              d     e       time
# 0  28000000000  2.50  03:46:40 
# 1  28100000000  2.54  13:33:20