Skip to content

Commit ca4fcdc

Browse files
committed
DOC: add example for tz_convert and tz_localize
1 parent 70094e3 commit ca4fcdc

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
@@ -10158,6 +10158,24 @@ def tz_convert(
1015810158
------
1015910159
TypeError
1016010160
If the axis is tz-naive.
10161+
10162+
Examples
10163+
--------
10164+
Change to another time zone:
10165+
10166+
>>> s = pd.Series([1],
10167+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10168+
>>> s.tz_convert('Asia/Shanghai')
10169+
2018-09-15 07:30:00+08:00 1
10170+
dtype: int64
10171+
10172+
Convert to UTC and get a tz-naive index:
10173+
10174+
>>> s = pd.Series([1],
10175+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10176+
>>> s.tz_convert(None)
10177+
2018-09-14 23:30:00 1
10178+
dtype: int64
1016110179
"""
1016210180
axis = self._get_axis_number(axis)
1016310181
ax = self._get_axis(axis)
@@ -10266,6 +10284,14 @@ def tz_localize(
1026610284
2018-09-15 01:30:00+02:00 1
1026710285
dtype: int64
1026810286
10287+
Convert to tz-naive index and preserve local time:
10288+
10289+
>>> s = pd.Series([1],
10290+
... index=pd.DatetimeIndex(['2018-09-15 01:30:00+02:00']))
10291+
>>> s.tz_localize(None)
10292+
2018-09-15 01:30:00 1
10293+
dtype: int64
10294+
1026910295
Be careful with DST changes. When there is sequential data, pandas
1027010296
can infer the DST time:
1027110297

0 commit comments

Comments
 (0)