如何将 UNIX 时间戳列表转换为 pandas 数据框中的日期时间对象列表?
How to convert a list of UNIX timestamps to a list of datetime objects in a pandas dataframe?
我有一个 pandas 数据框 df
,其中有一列包含格式为 1,475,761,269,562
的 UNIX 时间戳。
当我尝试将其转换为
df["Timestamp"] = pd.to_datetime(df["Timestamp"], unit = "s")
、
我正在
OverflowError: Long too big to convert
.
我做错了什么?
您需要 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
我有一个 pandas 数据框 df
,其中有一列包含格式为 1,475,761,269,562
的 UNIX 时间戳。
当我尝试将其转换为
df["Timestamp"] = pd.to_datetime(df["Timestamp"], unit = "s")
、
我正在
OverflowError: Long too big to convert
.
我做错了什么?
您需要 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