I have a DataFrame with two columns. One column is filled with timestamps, the other column contains the UTC offset in hours of the timestamp in the same row.
DataFrame is as follows:
In [44]: df Out[44]: DATETIME OFFSET 0 2013-01-01 00:00:00+00:00 1 1 2013-01-01 01:00:00+00:00 1 2 2013-01-01 02:00:00+00:00 1 3 2013-01-01 03:00:00+00:00 1 4 2013-01-01 04:00:00+00:00 1 5 2013-01-01 05:00:00+00:00 1 6 2013-01-01 06:00:00+00:00 2 7 2013-01-01 07:00:00+00:00 2 8 2013-01-01 08:00:00+00:00 2
What I like is to add the offset per line to the timestamp:
In [44]: df Out[44]: DATETIME OFFSET 0 2013-01-01 00:00:00+01:00 1 1 2013-01-01 01:00:00+01:00 1 2 2013-01-01 02:00:00+01:00 1 3 2013-01-01 03:00:00+01:00 1 4 2013-01-01 04:00:00+01:00 1 5 2013-01-01 05:00:00+01:00 1 6 2013-01-01 06:00:00+02:00 2 7 2013-01-01 07:00:00+02:00 2 8 2013-01-01 08:00:00+02:00 2
I tried replacing tzinfo but could not find the correct solution. I am thinking of something like the following (pseudocode):
df.apply(lambda x: x['DATETIME'].replace(tzinfo=pytz.utc + x['OFFSET'])
Any help is appreciated.
Thank you Thomas
source share