自Epoch以来,将Pandas Timestamp转换为nano的最有效方法是什么?
import pandas as pd
ns = 1470924597871000000
timestamp = pd.to_datetime(ns, unit="ns")
那么如何
timestamp => 1470924597871000000 ns???
对于我来说,它可以很好地使用参数unit
,但令人惊讶的是没有参数:
import pandas as pd
ns = 1470924597871000000
timestamp1 = pd.to_datetime(ns)
print (timestamp1)
2016-08-11 14:09:57.871000
timestamp = pd.to_datetime(ns, unit='ns')
print (timestamp)
2016-08-11 14:09:57.871000
如果需要从Timestamp转换为epoch:
print (timestamp.value)
1470924597871000000
您可以通过它的值访问它:
import pandas as pd
ns = 1470924597871000000
timestamp = pd.to_datetime(ns)
timestamp.value
Out: 1470924597871000000
传递unit='ns'
指定单元类型:
In [46]:
ns = 1470924597871000000
timestamp = pd.to_datetime(ns, unit='ns')
timestamp
Out[46]:
Timestamp('2016-08-11 14:09:57.871000')
,但这似乎工作得很好,无论如何没有传递这个,除非你是在别的东西之后?
您可以使用timestamp()
来获取时间戳值:
In [50]:
timestamp.timestamp()
Out[50]:
1470920997.871