Skip to content

Commit 050b5ac

Browse files
committed
DOC: add example for tz_convert and tz_localize
1 parent dd6ccb5 commit 050b5ac

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/core/generic.py

+26
Original file line numberDiff line numberDiff line change
@@ -10154,6 +10154,24 @@ def tz_convert(
1015410154
------
1015510155
TypeError
1015610156
If the axis is tz-naive.
10157+
10158+
Examples
10159+
--------
10160+
Change to another time zone:
10161+
10162+
>>> s = pd.Series([1],
10163+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10164+
>>> s.tz_convert('Asia/Shanghai')
10165+
2018-09-15 07:30:00+08:00 1
10166+
dtype: int64
10167+
10168+
Convert to UTC and get a tz-naive index:
10169+
10170+
>>> s = pd.Series([1],
10171+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10172+
>>> s.tz_convert(None)
10173+
2018-09-14 23:30:00 1
10174+
dtype: int64
1015710175
"""
1015810176
axis = self._get_axis_number(axis)
1015910177
ax = self._get_axis(axis)
@@ -10262,6 +10280,14 @@ def tz_localize(
1026210280
2018-09-15 01:30:00+02:00 1
1026310281
dtype: int64
1026410282
10283+
Convert to tz-naive index and preserve local time:
10284+
10285+
>>> s = pd.Series([1],
10286+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10287+
>>> s.tz_localize(None)
10288+
2018-09-15 01:30:00 1
10289+
dtype: int64
10290+
1026510291
Be careful with DST changes. When there is sequential data, pandas
1026610292
can infer the DST time:
1026710293

0 commit comments

Comments
 (0)