I have a set of 19 digit timestamps, stamp
, that I cannot figure out how to convert to a datetime format.
- For comparison,
stamp
corresponds todt
. - In the following code,
dt
has been converted to datetime and a unix timestamp.
I've read similar SO posts and it's not just a matter of dividing by 1,000,000,000. Also, it doesn't seem to be a double issue like from How to convert a really long timestamp into datetime (19 digits) (9876432101234567890).
Examples:
import pandas as pd
data = {'stamp': [1264604283246383104, 1266445459956158467, 1269744490329358337, 1270363071710715905],
'dt': ['May 24 2020 13:08 EST', 'May 29 2020 15:05 EST', 'Jun 7 2020 17:34 EST', 'Jun 9 2020 10:32 EST']}
df = pd.DataFrame(data)
# move timezone to a separate column
df['tz'] = df['dt'].str[-4:]
df['dt'] = df['dt'].str.replace(' EST', '')
# convert dt to UTC datetime
df['datetime'] = pd.to_datetime(df['dt']).dt.tz_localize(tz='US/Eastern').dt.tz_convert('UTC')
# convert datetime to unix datetime
df['datetime_unix'] = df['datetime'].astype(int)
stamp dt tz datetime datetime_unix
0 1264604283246383104 May 24 2020 13:08 EST 2020-05-24 17:08:00+00:00 1590340080000000000
1 1266445459956158467 May 29 2020 15:05 EST 2020-05-29 19:05:00+00:00 1590779100000000000
2 1269744490329358337 Jun 7 2020 17:34 EST 2020-06-07 21:34:00+00:00 1591565640000000000
3 1270363071710715905 Jun 9 2020 10:32 EST 2020-06-09 14:32:00+00:00 1591713120000000000
Thoughts on what this is and how to convert via Python?
- Converting unix timestamp string to readable date does not resolve the issue because it doesn't convert
stamp
to the correspondingdt
.