diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 969dcde9d792e..fa35060c8aff8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10139,7 +10139,9 @@ def tz_convert( Parameters ---------- - tz : str or tzinfo object + tz : str or tzinfo object or None + Target time zone. Passing ``None`` will convert to + UTC and remove the timezone information. axis : the axis to convert level : int, str, default None If axis is a MultiIndex, convert a specific level. Otherwise @@ -10156,6 +10158,24 @@ def tz_convert( ------ TypeError If the axis is tz-naive. + + 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 """ axis = self._get_axis_number(axis) ax = self._get_axis(axis) @@ -10206,7 +10226,9 @@ def tz_localize( Parameters ---------- - tz : str or tzinfo + tz : str or tzinfo or None + Time zone to localize. Passing ``None`` will remove the + time zone information and preserve local time. axis : the axis to localize level : int, str, default None If axis ia a MultiIndex, localize a specific level. Otherwise @@ -10262,6 +10284,14 @@ def tz_localize( 2018-09-15 01:30:00+02:00 1 dtype: int64 + Pass None to convert to tz-naive index and preserve local time: + + >>> s = pd.Series([1], + ... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00'])) + >>> s.tz_localize(None) + 2018-09-15 01:30:00 1 + dtype: int64 + Be careful with DST changes. When there is sequential data, pandas can infer the DST time: