@@ -1946,15 +1946,14 @@ def delete(self, loc):
1946
1946
1947
1947
def tz_convert (self , tz ):
1948
1948
"""
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.
1951
1950
1952
1951
Parameters
1953
1952
----------
1954
1953
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 .
1958
1957
1959
1958
Returns
1960
1959
-------
@@ -1964,6 +1963,50 @@ def tz_convert(self, tz):
1964
1963
------
1965
1964
TypeError
1966
1965
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')
1967
2010
"""
1968
2011
tz = timezones .maybe_get_tz (tz )
1969
2012
0 commit comments