我有一个pandas数据帧df
,其中包含一个格式为1,475,761,269,562
的UNIX时间戳的列。
当我尝试将其转换为
df["Timestamp"] = pd.to_datetime(df["Timestamp"], unit = "s")
,
我到了
OverflowError: Long too big to convert
。
我做错了什么?
答案 0 :(得分:1)
您需要unit='ms'
,或许replace
,
来清空字符串:
df = pd.DataFrame({'Timestamp':['1,475,761,269,562', '1,475,761,269,562']})
print (df)
Timestamp
0 1,475,761,269,562
1 1,475,761,269,562
df["Timestamp"] = pd.to_datetime(df["Timestamp"].str.replace(',',''), unit = "ms")
print (df)
Timestamp
0 2016-10-06 13:41:09.562
1 2016-10-06 13:41:09.562