I need to convert a timezone aware date_range (TimeStamps) to UNIX epoch values for use in an external Javascript library.
My approach is:
# Create localized test data for one day
rng = pd.date_range('1.1.2014', freq='H', periods=24, tz="Europe/Berlin")
val = np.random.randn(24)
df = pd.DataFrame(data=val, index=rng, columns=['values'])
# Reset index as df column
df = df.reset_index()
# Convert the index column to the desired UNIX epoch format
df['index'] = df['index'].apply(lambda x: x.value // 10**6 )
df['index'] contains the UNIX epoch values as expected but they are are stored in UTC(!).
I suppose this is because pandas stores timestamps in numpy UTC datetime64 values under the hood.
Is there a smart way to get "right" epoch values in the requested time zone?