MCPcopy
hub / github.com/pandas-dev/pandas / tz_convert

Method tz_convert

pandas/core/arrays/datetimes.py:860–940  ·  view source on GitHub ↗

Convert tz-aware Datetime Array/Index from one time zone to another. Parameters ---------- tz : str, zoneinfo.ZoneInfo, pytz.timezone, dateutil.tz.tzfile, datetime.tzinfo or None Time zone for time. Corresponding timestamps would be converted

(self, tz)

Source from the content-addressed store, hash-verified

858 return tz_convert_from_utc(self.asi8, self.tz, reso=self._creso)
859
860 def tz_convert(self, tz) -> Self:
861 """
862 Convert tz-aware Datetime Array/Index from one time zone to another.
863
864 Parameters
865 ----------
866 tz : str, zoneinfo.ZoneInfo, pytz.timezone, dateutil.tz.tzfile, datetime.tzinfo or None
867 Time zone for time. Corresponding timestamps would be converted
868 to this time zone of the Datetime Array/Index. A `tz` of None will
869 convert to UTC and remove the timezone information.
870
871 Returns
872 -------
873 Array or Index
874 Datetme Array/Index with target `tz`.
875
876 Raises
877 ------
878 TypeError
879 If Datetime Array/Index is tz-naive.
880
881 See Also
882 --------
883 DatetimeIndex.tz : A timezone that has a variable offset from UTC.
884 DatetimeIndex.tz_localize : Localize tz-naive DatetimeIndex to a
885 given time zone, or remove timezone from a tz-aware DatetimeIndex.
886
887 Examples
888 --------
889 With the `tz` parameter, we can change the DatetimeIndex
890 to other time zones:
891
892 >>> dti = pd.date_range(
893 ... start="2014-08-01 09:00", freq="h", periods=3, tz="Europe/Berlin"
894 ... )
895
896 >>> dti
897 DatetimeIndex(['2014-08-01 09:00:00+02:00',
898 '2014-08-01 10:00:00+02:00',
899 '2014-08-01 11:00:00+02:00'],
900 dtype='datetime64[us, Europe/Berlin]', freq='h')
901
902 >>> dti.tz_convert("US/Central")
903 DatetimeIndex(['2014-08-01 02:00:00-05:00',
904 '2014-08-01 03:00:00-05:00',
905 '2014-08-01 04:00:00-05:00'],
906 dtype='datetime64[us, US/Central]', freq='h')
907
908 With the ``tz=None``, we can remove the timezone (after converting
909 to UTC if necessary):
910
911 >>> dti = pd.date_range(
912 ... start="2014-08-01 09:00", freq="h", periods=3, tz="Europe/Berlin"
913 ... )
914
915 >>> dti
916 DatetimeIndex(['2014-08-01 09:00:00+02:00',
917 '2014-08-01 10:00:00+02:00',

Callers 6

_to_datetime_with_unitFunction · 0.45
to_datetimeFunction · 0.45
convert_valueMethod · 0.45
convert_valuesMethod · 0.45

Calls 2

_simple_newMethod · 0.95
tz_to_dtypeFunction · 0.85

Tested by

no test coverage detected