pandas.DataFrame.tz_convert#
- DataFrame.tz_convert(tz, axis=0, level=None, copy=<no_default>)[source]#
Convert tz-aware axis to target time zone.
- Parameters:
- tzstr or tzinfo object or None
Target time zone. Passing
Nonewill convert to UTC and remove the timezone information.- axis{0 or ‘index’, 1 or ‘columns’}, default 0
The axis to convert
- levelint, str, default None
If axis is a MultiIndex, convert a specific level. Otherwise must be None.
- copybool, default False
This keyword is now ignored; changing its value will have no impact on the method.
Deprecated since version 3.0.0: This keyword is ignored and will be removed in pandas 4.0. Since pandas 3.0, this method always returns a new object using a lazy copy mechanism that defers copies until necessary (Copy-on-Write). See the user guide on Copy-on-Write for more details.
- Returns:
- Series/DataFrame
Object with time zone converted axis.
- Raises:
- TypeError
If the axis is tz-naive.
See also
DataFrame.tz_localizeLocalize tz-naive index of DataFrame to target time zone.
Series.tz_localizeLocalize tz-naive index of Series to target time zone.
Examples
Change to another time zone:
>>> s = pd.Series( ... [1], ... index=pd.DatetimeIndex(["2018-09-15 01:30:00+02:00"]), ... ) >>> s.tz_convert("Asia/Shanghai") 2018-09-15 07:30:00+08:00 1 dtype: int64
Pass None to convert to UTC and get a tz-naive index:
>>> s = pd.Series([1], index=pd.DatetimeIndex(["2018-09-15 01:30:00+02:00"])) >>> s.tz_convert(None) 2018-09-14 23:30:00 1 dtype: int64