@@ -10139,7 +10139,9 @@ def tz_convert(
10139
10139
10140
10140
Parameters
10141
10141
----------
10142
- tz : str or tzinfo object
10142
+ tz : str or tzinfo object or None
10143
+ Target time zone. Passing ``None`` will convert to
10144
+ UTC and remove the timezone information.
10143
10145
axis : the axis to convert
10144
10146
level : int, str, default None
10145
10147
If axis is a MultiIndex, convert a specific level. Otherwise
@@ -10156,6 +10158,24 @@ def tz_convert(
10156
10158
------
10157
10159
TypeError
10158
10160
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
+ Pass None to 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
10159
10179
"""
10160
10180
axis = self ._get_axis_number (axis )
10161
10181
ax = self ._get_axis (axis )
@@ -10206,7 +10226,9 @@ def tz_localize(
10206
10226
10207
10227
Parameters
10208
10228
----------
10209
- tz : str or tzinfo
10229
+ tz : str or tzinfo or None
10230
+ Time zone to localize. Passing ``None`` will remove the
10231
+ time zone information and preserve local time.
10210
10232
axis : the axis to localize
10211
10233
level : int, str, default None
10212
10234
If axis ia a MultiIndex, localize a specific level. Otherwise
@@ -10262,6 +10284,14 @@ def tz_localize(
10262
10284
2018-09-15 01:30:00+02:00 1
10263
10285
dtype: int64
10264
10286
10287
+ Pass None to 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
+
10265
10295
Be careful with DST changes. When there is sequential data, pandas
10266
10296
can infer the DST time:
10267
10297
0 commit comments