What is the most efficient way to convert Pandas Timestamp into nano since Epoch?
import pandas as pd
ns = 1470924597871000000
timestamp = pd.to_datetime(ns, unit="ns")
Then how to
timestamp => 1470924597871000000 ns???
For me it works nice with parameter unit
but surprisingly without parameter too:
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
And if need convert from Timestamp to epoch:
print (timestamp.value)
1470924597871000000
You can access it via its value:
import pandas as pd
ns = 1470924597871000000
timestamp = pd.to_datetime(ns)
timestamp.value
Out: 1470924597871000000
pass unit='ns'
to specify the unit type:
In [46]:
ns = 1470924597871000000
timestamp = pd.to_datetime(ns, unit='ns')
timestamp
Out[46]:
Timestamp('2016-08-11 14:09:57.871000')
but this seems to work fine anyway without passing this unless you are after something else?
You can use timestamp()
to get the timestamp value:
In [50]:
timestamp.timestamp()
Out[50]:
1470920997.871
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With