Home > Mobile >  How extract a hour from converted timzone timestamp in pandas
How extract a hour from converted timzone timestamp in pandas

Time:09-01

At the beginning I have a UTC timestamp and from that I want to

  1. convert the timestamp to "Europe/Vienna" timezone
  2. want to extract the already converted hour based on "Europe/Vienna" timezone

enter image description here

As you can see I have already converted the timestamp to "Europe/Vienna" but when I want to extract the hour with df_entsoe_commexch_aggregated['index'].hour I will always get the origin hour. See below... enter image description here

CodePudding user response:

It is doing exactly what you want. 23:00:00 02:00 for Europe/Vienna means that it is 23:00:00 in Europe/Vienna which is 2 hours later than the origin (i.e. UTC).

As example, copied from the documentation:

>>> dti = pd.date_range(start='2014-08-01 09:00', freq='H', periods=3, tz='Europe/Berlin')
>>> dti
DatetimeIndex(['2014-08-01 09:00:00 02:00',
               '2014-08-01 10:00:00 02:00',
               '2014-08-01 11:00:00 02:00'],
              dtype='datetime64[ns, Europe/Berlin]', freq='H')
>>> dti.tz_convert('US/Central')
DatetimeIndex(['2014-08-01 02:00:00-05:00',
               '2014-08-01 03:00:00-05:00',
               '2014-08-01 04:00:00-05:00'],
              dtype='datetime64[ns, US/Central]', freq='H')
>>> dti.tz_convert(None)
DatetimeIndex(['2014-08-01 07:00:00',
               '2014-08-01 08:00:00',
               '2014-08-01 09:00:00'],
                dtype='datetime64[ns]', freq='H')
  • Related