Python 纪元纳秒到正常时间

Python 纪元纳秒到正常时间,python,python-2.7,pandas,datetime,epoch,Python,Python 2.7,Pandas,Datetime,Epoch,我有一份数据 name time 0 acn 1530677359000000000 1 acn 1530677363000000000 2 acn 1530681023000000000 3 acn 1530681053000000000 4 acn 1530681531000000000 5 acn 1530681561000000000 因此,我想将time列更改为datetime格式 我尝试通过执行以下命令来执行此操作: df[

我有一份数据

name        time
0   acn  1530677359000000000
1   acn  1530677363000000000 
2   acn  1530681023000000000 
3   acn  1530681053000000000 
4   acn  1530681531000000000 
5   acn  1530681561000000000
因此,我想将
time
列更改为
datetime
格式

我尝试通过执行以下命令来执行此操作:

df['time']=pd.to_datetime(df['time'])

但它给出了不正确的输出,如:

Out[70]:
02078-09-01 09:55:28.826007552
12078-10-17 17:02:08.826007552
22194-10-1019:42:08.826007552
3 2195-09-23 01:02:08.826007552
42210-11-16 10:48:48.826007552
52211-10-2916:08:48.826007552

我使用的是python 2.7。请看一看。

矢量化,您可以与
unit='ns'
一起使用

import datetime

df.time = df.time.apply(lambda x: datetime.datetime.fromtimestamp(x / 1e9))
df['datetime'] = pd.to_datetime(df['time'], unit='ns')

print(df)

  name                 time            datetime
0  acn  1530677359000000000 2018-07-04 04:09:19
1  acn  1530677363000000000 2018-07-04 04:09:23
2  acn  1530681023000000000 2018-07-04 05:10:23
3  acn  1530681053000000000 2018-07-04 05:10:53
4  acn  1530681531000000000 2018-07-04 05:18:51
5  acn  1530681561000000000 2018-07-04 05:19:21
pd.to_datetime(153067735900000000,单位为''ns')