Skip to content

Commit 1837929

Browse files
hammadmashkoorTomAugspurger
authored andcommitted
DOC: update the DatetimeIndex.tz_convert(tz) docstring (#20096)
1 parent b1c113f commit 1837929

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

pandas/core/indexes/datetimes.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,15 +1946,14 @@ def delete(self, loc):
19461946

19471947
def tz_convert(self, tz):
19481948
"""
1949-
Convert tz-aware DatetimeIndex from one time zone to another (using
1950-
pytz/dateutil)
1949+
Convert tz-aware DatetimeIndex from one time zone to another.
19511950
19521951
Parameters
19531952
----------
19541953
tz : string, pytz.timezone, dateutil.tz.tzfile or None
1955-
Time zone for time. Corresponding timestamps would be converted to
1956-
time zone of the TimeSeries.
1957-
None will remove timezone holding UTC time.
1954+
Time zone for time. Corresponding timestamps would be converted
1955+
to this time zone of the DatetimeIndex. A `tz` of None will
1956+
convert to UTC and remove the timezone information.
19581957
19591958
Returns
19601959
-------
@@ -1964,6 +1963,50 @@ def tz_convert(self, tz):
19641963
------
19651964
TypeError
19661965
If DatetimeIndex is tz-naive.
1966+
1967+
See Also
1968+
--------
1969+
DatetimeIndex.tz : A timezone that has a variable offset from UTC
1970+
DatetimeIndex.tz_localize : Localize tz-naive DatetimeIndex to a
1971+
given time zone, or remove timezone from a tz-aware DatetimeIndex.
1972+
1973+
Examples
1974+
--------
1975+
With the `tz` parameter, we can change the DatetimeIndex
1976+
to other time zones:
1977+
1978+
>>> dti = pd.DatetimeIndex(start='2014-08-01 09:00',
1979+
... freq='H', periods=3, tz='Europe/Berlin')
1980+
1981+
>>> dti
1982+
DatetimeIndex(['2014-08-01 09:00:00+02:00',
1983+
'2014-08-01 10:00:00+02:00',
1984+
'2014-08-01 11:00:00+02:00'],
1985+
dtype='datetime64[ns, Europe/Berlin]', freq='H')
1986+
1987+
>>> dti.tz_convert('US/Central')
1988+
DatetimeIndex(['2014-08-01 02:00:00-05:00',
1989+
'2014-08-01 03:00:00-05:00',
1990+
'2014-08-01 04:00:00-05:00'],
1991+
dtype='datetime64[ns, US/Central]', freq='H')
1992+
1993+
With the ``tz=None``, we can remove the timezone (after converting
1994+
to UTC if necessary):
1995+
1996+
>>> dti = pd.DatetimeIndex(start='2014-08-01 09:00',freq='H',
1997+
... periods=3, tz='Europe/Berlin')
1998+
1999+
>>> dti
2000+
DatetimeIndex(['2014-08-01 09:00:00+02:00',
2001+
'2014-08-01 10:00:00+02:00',
2002+
'2014-08-01 11:00:00+02:00'],
2003+
dtype='datetime64[ns, Europe/Berlin]', freq='H')
2004+
2005+
>>> dti.tz_convert(None)
2006+
DatetimeIndex(['2014-08-01 07:00:00',
2007+
'2014-08-01 08:00:00',
2008+
'2014-08-01 09:00:00'],
2009+
dtype='datetime64[ns]', freq='H')
19672010
"""
19682011
tz = timezones.maybe_get_tz(tz)
19692012

0 commit comments

Comments
 (0)