A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pandas.pydata.org/docs/reference/api/pandas.DatetimeIndex.tz_convert.html below:

pandas.DatetimeIndex.tz_convert — pandas 2.3.1 documentation

pandas.DatetimeIndex.tz_convert#
DatetimeIndex.tz_convert(tz)[source]#

Convert tz-aware Datetime Array/Index from one time zone to another.

Parameters:
tzstr, pytz.timezone, dateutil.tz.tzfile, datetime.tzinfo or None

Time zone for time. Corresponding timestamps would be converted to this time zone of the Datetime Array/Index. A tz of None will convert to UTC and remove the timezone information.

Returns:
Array or Index
Raises:
TypeError

If Datetime Array/Index is tz-naive.

Examples

With the tz parameter, we can change the DatetimeIndex to other time zones:

>>> 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')

With the tz=None, we can remove the timezone (after converting to UTC if necessary):

>>> 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(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')

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4