I have read a large csv file into a Jupyter notebook, and it contains a column of 16 digit numbers (e.g. 1352160000000000) as an Epoch/Unix timestamp.
I have checked this number on an online Epoch/Unix timestamp converter site and it returns the time I know it should (GMT: Tuesday, November 6, 2012 12:00:00 AM).
I then used the following code (adapted from other answers to this question on this site): df['TIME'] = pd.to_datetime(df['TIME'], unit='u') to convert this number to human readable form in my data frame but I either get an error, or I get (1970-01-16 15:36:00.000).
Can anyone point out to me where it is I am going wrong, and what I am missing?
You need to use 'us' unit.
df['TIME'] = pd.to_datetime(df['TIME'], unit='us')
pd.to_datetime(1352160000000000,unit='us')
Out[24]: Timestamp('2012-11-06 00:00:00')
The unit is microseconds, so you should use 'us' as unit:
pd.to_datetime(1352160000000000, unit='us')
for example:
>>> pd.to_datetime(1352160000000000, unit='us')
Timestamp('2012-11-06 00:00:00')
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