From b062d66196b1a8aa6d16e47d8b70942b62fe60a8 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 10 Mar 2018 02:23:25 +0530 Subject: [PATCH 01/11] Added Docstring for DatetimeIndex.tz_convert(tz) --- pandas/core/indexes/datetimes.py | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e5e9bba269fd4..0ce63c3c51cbc 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1904,8 +1904,11 @@ def delete(self, loc): def tz_convert(self, tz): """ - Convert tz-aware DatetimeIndex from one time zone to another (using - pytz/dateutil) + A Method to Convert tz-aware DatetimeIndex from one time zone to another. + + When using DatetimeIndex providing with timezone + this method converts tz-aware DatetimeIndex using + pytz/dateutil. Parameters ---------- @@ -1917,11 +1920,31 @@ def tz_convert(self, tz): Returns ------- normalized : DatetimeIndex - - Raises - ------ + + Raises + ------- TypeError If DatetimeIndex is tz-naive. + + See Also + -------- + tz_localize : Localize tz-naive DatetimeIndex to given time zone (using pytz/dateutil), + or remove timezone from tz-aware DatetimeIndex. + + Examples + -------- + >>> datetime=pd.Series(pd.date_range('20180301',periods=3)) + >>> datetime + 0 2018-03-01 + 1 2018-03-02 + 2 2018-03-03 + dtype: datetime64[ns] + + >>> datetime.dt.tz_localize('UTC').dt.tz_convert('US/Eastern') + 0 2018-02-28 19:00:00-05:00 + 1 2018-03-01 19:00:00-05:00 + 2 2018-03-02 19:00:00-05:00 + dtype: datetime64[ns, US/Eastern] """ tz = timezones.maybe_get_tz(tz) From d16d9efebf5ff8c89815f506bbddd68d46df49a4 Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Sat, 10 Mar 2018 11:15:47 +0530 Subject: [PATCH 02/11] Doc:added for TimedateIndex.tz_convert(tz) --- pandas/core/indexes/datetimes.py | 51 ++++++++++++++++---------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 0ce63c3c51cbc..e0660fc5f6896 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1904,47 +1904,48 @@ def delete(self, loc): def tz_convert(self, tz): """ - A Method to Convert tz-aware DatetimeIndex from one time zone to another. - - When using DatetimeIndex providing with timezone - this method converts tz-aware DatetimeIndex using - pytz/dateutil. + Convert tz-aware DatetimeIndex from one + time zone to another. + + When using DatetimeIndex providing with timezone this method + converts tz-aware DatetimeIndex using pytz/dateutil. Parameters ---------- tz : string, pytz.timezone, dateutil.tz.tzfile or None - Time zone for time. Corresponding timestamps would be converted to - time zone of the TimeSeries. + Time zone for time.Corresponding timestamps would be converted + to time zone of the TimeSeries. None will remove timezone holding UTC time. Returns ------- normalized : DatetimeIndex - - Raises + + Raises ------- TypeError If DatetimeIndex is tz-naive. - See Also + See Also -------- - tz_localize : Localize tz-naive DatetimeIndex to given time zone (using pytz/dateutil), - or remove timezone from tz-aware DatetimeIndex. + tz_localize : Localize tz-naive DatetimeIndex to given time zone + (using pytz/dateutil),or remove timezone from tz-aware + DatetimeIndex. - Examples + Examples -------- - >>> datetime=pd.Series(pd.date_range('20180301',periods=3)) - >>> datetime - 0 2018-03-01 - 1 2018-03-02 - 2 2018-03-03 - dtype: datetime64[ns] - - >>> datetime.dt.tz_localize('UTC').dt.tz_convert('US/Eastern') - 0 2018-02-28 19:00:00-05:00 - 1 2018-03-01 19:00:00-05:00 - 2 2018-03-02 19:00:00-05:00 - dtype: datetime64[ns, US/Eastern] + >>> datetime=pd.Series(pd.date_range('20180301',periods=3)) + >>> datetime + 0 2018-03-01 + 1 2018-03-02 + 2 2018-03-03 + dtype: datetime64[ns] + + >>> datetime.dt.tz_localize('UTC').dt.tz_convert('US/Eastern') + 0 2018-02-28 19:00:00-05:00 + 1 2018-03-01 19:00:00-05:00 + 2 2018-03-02 19:00:00-05:00 + dtype: datetime64[ns, US/Eastern] """ tz = timezones.maybe_get_tz(tz) From 74ba82ade18cf5e3870fa6cd3d50838d4942620a Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Sat, 10 Mar 2018 15:08:19 +0530 Subject: [PATCH 03/11] Update Docstring --- pandas/core/indexes/datetimes.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e0660fc5f6896..e9f3f26ac0792 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1904,11 +1904,10 @@ def delete(self, loc): def tz_convert(self, tz): """ - Convert tz-aware DatetimeIndex from one - time zone to another. + Convert tz(timezone)-aware DatetimeIndex using pytz/dateutil. When using DatetimeIndex providing with timezone this method - converts tz-aware DatetimeIndex using pytz/dateutil. + converts tz-aware DatetimeIndex from one timezone to another. Parameters ---------- From 4f7a570dae5e601e091a4ccda6e8059f06044b3b Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Sat, 10 Mar 2018 17:09:51 +0530 Subject: [PATCH 04/11] Updated on recent comments --- pandas/core/indexes/datetimes.py | 49 +++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e9f3f26ac0792..8626472573da3 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1904,15 +1904,16 @@ def delete(self, loc): def tz_convert(self, tz): """ - Convert tz(timezone)-aware DatetimeIndex using pytz/dateutil. + Convert tz-aware DatetimeIndex from one time zone to another. When using DatetimeIndex providing with timezone this method - converts tz-aware DatetimeIndex from one timezone to another. + converts tz(timezone)-aware DatetimeIndex from one timezone + to another using pytz/dateutil. Parameters ---------- tz : string, pytz.timezone, dateutil.tz.tzfile or None - Time zone for time.Corresponding timestamps would be converted + Time zone for time. Corresponding timestamps would be converted to time zone of the TimeSeries. None will remove timezone holding UTC time. @@ -1921,30 +1922,44 @@ def tz_convert(self, tz): normalized : DatetimeIndex Raises - ------- + ------ TypeError If DatetimeIndex is tz-naive. See Also -------- tz_localize : Localize tz-naive DatetimeIndex to given time zone - (using pytz/dateutil),or remove timezone from tz-aware + (using pytz/dateutil), or remove timezone from tz-aware DatetimeIndex. Examples -------- - >>> datetime=pd.Series(pd.date_range('20180301',periods=3)) - >>> datetime - 0 2018-03-01 - 1 2018-03-02 - 2 2018-03-03 - dtype: datetime64[ns] - - >>> datetime.dt.tz_localize('UTC').dt.tz_convert('US/Eastern') - 0 2018-02-28 19:00:00-05:00 - 1 2018-03-01 19:00:00-05:00 - 2 2018-03-02 19:00:00-05:00 - dtype: datetime64[ns, US/Eastern] + >>> didx = pd.DatetimeIndex + (start='2014-08-01 09:00', freq='H', periods=10, tz='Europe/Berlin') + + >>> didx + DatetimeIndex(['2014-08-01 09:00:00+02:00','2014-08-01 10:00:00+02:00', + '2014-08-01 11:00:00+02:00', '2014-08-01 12:00:00+02:00', + '2014-08-01 13:00:00+02:00', '2014-08-01 14:00:00+02:00', + '2014-08-01 15:00:00+02:00', '2014-08-01 16:00:00+02:00', + '2014-08-01 17:00:00+02:00', '2014-08-01 18:00:00+02:00'], + dtype='datetime64[ns, Europe/Berlin]', freq='H') + + >>> didx.tz_convert('US/Eastern') + DatetimeIndex(['2014-08-01 03:00:00-04:00','2014-08-01 04:00:00-04:00', + '2014-08-01 05:00:00-04:00', '2014-08-01 06:00:00-04:00', + '2014-08-01 07:00:00-04:00', '2014-08-01 08:00:00-04:00', + '2014-08-01 09:00:00-04:00', '2014-08-01 10:00:00-04:00', + '2014-08-01 11:00:00-04:00', '2014-08-01 12:00:00-04:00'], + dtype='datetime64[ns, US/Eastern]', freq='H') + + >>> didx.tz_convert(None) + DatetimeIndex(['2014-08-01 07:00:00','2014-08-01 08:00:00', + '2014-08-01 09:00:00', '2014-08-01 10:00:00', + '2014-08-01 11:00:00', '2014-08-01 12:00:00', + '2014-08-01 13:00:00', '2014-08-01 14:00:00', + '2014-08-01 15:00:00', '2014-08-01 16:00:00'], + dtype='datetime64[ns]', freq='H') """ tz = timezones.maybe_get_tz(tz) From 7a003def0ccbbc064d08bbc020f76f093b92dab3 Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Sat, 10 Mar 2018 19:50:41 +0530 Subject: [PATCH 05/11] Updated under comments --- pandas/core/indexes/datetimes.py | 53 ++++++++++++++++---------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 8626472573da3..f84c1c293024c 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1908,7 +1908,7 @@ def tz_convert(self, tz): When using DatetimeIndex providing with timezone this method converts tz(timezone)-aware DatetimeIndex from one timezone - to another using pytz/dateutil. + to another. Parameters ---------- @@ -1934,32 +1934,31 @@ def tz_convert(self, tz): Examples -------- - >>> didx = pd.DatetimeIndex - (start='2014-08-01 09:00', freq='H', periods=10, tz='Europe/Berlin') - - >>> didx - DatetimeIndex(['2014-08-01 09:00:00+02:00','2014-08-01 10:00:00+02:00', - '2014-08-01 11:00:00+02:00', '2014-08-01 12:00:00+02:00', - '2014-08-01 13:00:00+02:00', '2014-08-01 14:00:00+02:00', - '2014-08-01 15:00:00+02:00', '2014-08-01 16:00:00+02:00', - '2014-08-01 17:00:00+02:00', '2014-08-01 18:00:00+02:00'], - dtype='datetime64[ns, Europe/Berlin]', freq='H') - - >>> didx.tz_convert('US/Eastern') - DatetimeIndex(['2014-08-01 03:00:00-04:00','2014-08-01 04:00:00-04:00', - '2014-08-01 05:00:00-04:00', '2014-08-01 06:00:00-04:00', - '2014-08-01 07:00:00-04:00', '2014-08-01 08:00:00-04:00', - '2014-08-01 09:00:00-04:00', '2014-08-01 10:00:00-04:00', - '2014-08-01 11:00:00-04:00', '2014-08-01 12:00:00-04:00'], - dtype='datetime64[ns, US/Eastern]', freq='H') - - >>> didx.tz_convert(None) - DatetimeIndex(['2014-08-01 07:00:00','2014-08-01 08:00:00', - '2014-08-01 09:00:00', '2014-08-01 10:00:00', - '2014-08-01 11:00:00', '2014-08-01 12:00:00', - '2014-08-01 13:00:00', '2014-08-01 14:00:00', - '2014-08-01 15:00:00', '2014-08-01 16:00:00'], - dtype='datetime64[ns]', freq='H') + >>> data=pd.DatetimeIndex(start='2014-08-01 09:00', + ... freq='H', periods=3, tz='Europe/Berlin') + + >>> data + DatetimeIndex(['2014-08-01 09:00:00+02:00', + '2014-08-01 10:00:00+02:00', + '2014-08-01 11:00:00+02:00'], + dtype='datetime64[ns, Europe/Berlin]', freq='H') + + With the `tz` parameter, we can change DatetimeIndex + to other time zones: + + >>> data.tz_convert('US/Eastern') + DatetimeIndex(['2014-08-01 03:00:00-04:00', + '2014-08-01 04:00:00-04:00', + '2014-08-01 05:00:00-04:00'], + dtype='datetime64[ns, US/Eastern]', freq='H') + + With the `None` parameter, we can remove timezone: + + >>> data.tz_convert(None) + DatetimeIndex(['2014-08-01 07:00:00', + '2014-08-01 08:00:00', + '2014-08-01 09:00:00'], + dtype='datetime64[ns]', freq='H') """ tz = timezones.maybe_get_tz(tz) From fac254453a745f45b3e056c630102cd9e8d1813f Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Sat, 10 Mar 2018 20:25:12 +0530 Subject: [PATCH 06/11] Updated under recommendations --- pandas/core/indexes/datetimes.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index f84c1c293024c..cd4fb51db68b4 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1914,7 +1914,7 @@ def tz_convert(self, tz): ---------- tz : string, pytz.timezone, dateutil.tz.tzfile or None Time zone for time. Corresponding timestamps would be converted - to time zone of the TimeSeries. + to time zone of the DatetimeIndex. None will remove timezone holding UTC time. Returns @@ -1928,9 +1928,8 @@ def tz_convert(self, tz): See Also -------- - tz_localize : Localize tz-naive DatetimeIndex to given time zone - (using pytz/dateutil), or remove timezone from tz-aware - DatetimeIndex. + tz_localize : Localize tz-naive DatetimeIndex to given time zone, + or remove timezone from tz-aware DatetimeIndex. Examples -------- @@ -1943,7 +1942,7 @@ def tz_convert(self, tz): '2014-08-01 11:00:00+02:00'], dtype='datetime64[ns, Europe/Berlin]', freq='H') - With the `tz` parameter, we can change DatetimeIndex + With the `tz` parameter, we can change the DatetimeIndex to other time zones: >>> data.tz_convert('US/Eastern') @@ -1952,7 +1951,7 @@ def tz_convert(self, tz): '2014-08-01 05:00:00-04:00'], dtype='datetime64[ns, US/Eastern]', freq='H') - With the `None` parameter, we can remove timezone: + With the `None` parameter, we can remove the timezone: >>> data.tz_convert(None) DatetimeIndex(['2014-08-01 07:00:00', From 236e00b4c18928888f2c82ee17ed32164bc1b6d7 Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Sat, 10 Mar 2018 21:24:21 +0530 Subject: [PATCH 07/11] Updated under recommendations --- pandas/core/indexes/datetimes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index cd4fb51db68b4..ce5da4726df31 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1933,10 +1933,10 @@ def tz_convert(self, tz): Examples -------- - >>> data=pd.DatetimeIndex(start='2014-08-01 09:00', + >>> dti = pd.DatetimeIndex(start='2014-08-01 09:00', ... freq='H', periods=3, tz='Europe/Berlin') - >>> data + >>> dti DatetimeIndex(['2014-08-01 09:00:00+02:00', '2014-08-01 10:00:00+02:00', '2014-08-01 11:00:00+02:00'], @@ -1945,7 +1945,7 @@ def tz_convert(self, tz): With the `tz` parameter, we can change the DatetimeIndex to other time zones: - >>> data.tz_convert('US/Eastern') + >>> dti.tz_convert('US/Eastern') DatetimeIndex(['2014-08-01 03:00:00-04:00', '2014-08-01 04:00:00-04:00', '2014-08-01 05:00:00-04:00'], @@ -1953,7 +1953,7 @@ def tz_convert(self, tz): With the `None` parameter, we can remove the timezone: - >>> data.tz_convert(None) + >>> dti.tz_convert(None) DatetimeIndex(['2014-08-01 07:00:00', '2014-08-01 08:00:00', '2014-08-01 09:00:00'], From 1b563425c25eb143afb0e274ca586bd9a7548a59 Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Sat, 10 Mar 2018 22:10:30 +0530 Subject: [PATCH 08/11] Updated under recommendations --- pandas/core/indexes/datetimes.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index ce5da4726df31..e0a9228945859 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1933,19 +1933,19 @@ def tz_convert(self, tz): Examples -------- + With the `tz` parameter, we can change the DatetimeIndex + to other time zones: + >>> dti = pd.DatetimeIndex(start='2014-08-01 09:00', - ... freq='H', periods=3, tz='Europe/Berlin') + ... freq='H', periods=3) >>> dti - DatetimeIndex(['2014-08-01 09:00:00+02:00', - '2014-08-01 10:00:00+02:00', - '2014-08-01 11:00:00+02:00'], - dtype='datetime64[ns, Europe/Berlin]', freq='H') - - With the `tz` parameter, we can change the DatetimeIndex - to other time zones: + DatetimeIndex(['2014-08-01 09:00:00', + '2014-08-01 10:00:00', + '2014-08-01 11:00:00'], + dtype='datetime64[ns]', freq='H') - >>> dti.tz_convert('US/Eastern') + >>> dti.tz_localize('Europe/Berlin').tz_convert('US/Eastern') DatetimeIndex(['2014-08-01 03:00:00-04:00', '2014-08-01 04:00:00-04:00', '2014-08-01 05:00:00-04:00'], @@ -1953,6 +1953,15 @@ def tz_convert(self, tz): With the `None` parameter, we can remove the timezone: + >>> dti = pd.DatetimeIndex(start='2014-08-01 09:00',freq='H', + ... periods=3, tz='Europe/Berlin') + + >>> dti + DatetimeIndex(['2014-08-01 09:00:00+02:00', + '2014-08-01 10:00:00+02:00', + '2014-08-01 11:00:00+02:00'], + dtype='datetime64[ns, Europe/Berlin]', freq='H') + >>> dti.tz_convert(None) DatetimeIndex(['2014-08-01 07:00:00', '2014-08-01 08:00:00', From f8e4024aa33c28a5ae87cabb92d712ee84ec24dc Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Sat, 10 Mar 2018 22:40:58 +0530 Subject: [PATCH 09/11] Updated under recommendations --- pandas/core/indexes/datetimes.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e0a9228945859..634b4b1562096 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1945,11 +1945,11 @@ def tz_convert(self, tz): '2014-08-01 11:00:00'], dtype='datetime64[ns]', freq='H') - >>> dti.tz_localize('Europe/Berlin').tz_convert('US/Eastern') - DatetimeIndex(['2014-08-01 03:00:00-04:00', - '2014-08-01 04:00:00-04:00', - '2014-08-01 05:00:00-04:00'], - dtype='datetime64[ns, US/Eastern]', freq='H') + >>> dti.tz_localize('Europe/Berlin') + DatetimeIndex(['2014-08-01 09:00:00+02:00', + '2014-08-01 10:00:00+02:00', + '2014-08-01 11:00:00+02:00'], + dtype='datetime64[ns, Europe/Berlin]', freq='H') With the `None` parameter, we can remove the timezone: From 1f0adfc339ee3307a8624f6b5bdac6f5b3c9301a Mon Sep 17 00:00:00 2001 From: Hammad Mashkoor Date: Tue, 13 Mar 2018 16:14:48 +0530 Subject: [PATCH 10/11] Updated --- pandas/core/indexes/datetimes.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index ea03ef2cb3f20..188dcaf12dd96 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1948,15 +1948,11 @@ def tz_convert(self, tz): """ Convert tz-aware DatetimeIndex from one time zone to another. - When using DatetimeIndex providing with timezone this method - converts tz(timezone)-aware DatetimeIndex from one timezone - to another. - Parameters ---------- tz : string, pytz.timezone, dateutil.tz.tzfile or None Time zone for time. Corresponding timestamps would be converted - to time zone of the DatetimeIndex. + to this time zone of the DatetimeIndex. None will remove timezone holding UTC time. Returns @@ -1970,8 +1966,8 @@ def tz_convert(self, tz): See Also -------- - tz_localize : Localize tz-naive DatetimeIndex to given time zone, - or remove timezone from tz-aware DatetimeIndex. + tz_localize : Localize tz-naive DatetimeIndex to a given time zone, + or remove timezone from a tz-aware DatetimeIndex. Examples -------- From ff006651a4dc21ac7480eb8d7e64e65d782a92c5 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 13 Mar 2018 07:11:26 -0500 Subject: [PATCH 11/11] Formatting on tz Formatting on See Also Added tz PEP8 on example Switched to tz_convert --- pandas/core/indexes/datetimes.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 188dcaf12dd96..1dca7bc47c274 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1952,8 +1952,8 @@ def tz_convert(self, tz): ---------- tz : string, pytz.timezone, dateutil.tz.tzfile or None Time zone for time. Corresponding timestamps would be converted - to this time zone of the DatetimeIndex. - None will remove timezone holding UTC time. + to this time zone of the DatetimeIndex. A `tz` of None will + convert to UTC and remove the timezone information. Returns ------- @@ -1966,8 +1966,9 @@ def tz_convert(self, tz): See Also -------- - tz_localize : Localize tz-naive DatetimeIndex to a given time zone, - or remove timezone from a tz-aware DatetimeIndex. + DatetimeIndex.tz : A timezone that has a variable offset from UTC + DatetimeIndex.tz_localize : Localize tz-naive DatetimeIndex to a + given time zone, or remove timezone from a tz-aware DatetimeIndex. Examples -------- @@ -1975,21 +1976,22 @@ def tz_convert(self, tz): to other time zones: >>> dti = pd.DatetimeIndex(start='2014-08-01 09:00', - ... freq='H', periods=3) + ... freq='H', periods=3, tz='Europe/Berlin') >>> dti - DatetimeIndex(['2014-08-01 09:00:00', - '2014-08-01 10:00:00', - '2014-08-01 11:00:00'], - dtype='datetime64[ns]', freq='H') - - >>> dti.tz_localize('Europe/Berlin') DatetimeIndex(['2014-08-01 09:00:00+02:00', '2014-08-01 10:00:00+02:00', '2014-08-01 11:00:00+02:00'], - dtype='datetime64[ns, Europe/Berlin]', freq='H') + dtype='datetime64[ns, Europe/Berlin]', freq='H') + + >>> dti.tz_convert('US/Central') + DatetimeIndex(['2014-08-01 02:00:00-05:00', + '2014-08-01 03:00:00-05:00', + '2014-08-01 04:00:00-05:00'], + dtype='datetime64[ns, US/Central]', freq='H') - With the `None` parameter, we can remove the timezone: + With the ``tz=None``, we can remove the timezone (after converting + to UTC if necessary): >>> dti = pd.DatetimeIndex(start='2014-08-01 09:00',freq='H', ... periods=3, tz='Europe/Berlin')