Skip to content

Commit e6b9004

Browse files
DOC: timezone conversion example added to pandas.Series.astype doc pandas-dev#33399
1 parent 610568c commit e6b9004

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/core/generic.py

+18
Original file line numberDiff line numberDiff line change
@@ -5538,6 +5538,24 @@ def astype(
55385538
0 10
55395539
1 2
55405540
dtype: int64
5541+
5542+
Create a series of dates:
5543+
5544+
>>> ser_date = pd.Series(pd.date_range('20200101', periods=3))
5545+
>>> ser_date
5546+
0 2020-01-01
5547+
1 2020-01-02
5548+
2 2020-01-03
5549+
dtype: datetime64[ns]
5550+
5551+
Convert to datetime type with time zone:
5552+
5553+
>>> # localize to UTC and convert to US/Eastern time zone
5554+
>>> ser_date.astype('datetime64[ns, US/Eastern]')
5555+
0 2019-12-31 19:00:00-05:00
5556+
1 2020-01-01 19:00:00-05:00
5557+
2 2020-01-02 19:00:00-05:00
5558+
dtype: datetime64[ns, US/Eastern]
55415559
"""
55425560
if is_dict_like(dtype):
55435561
if self.ndim == 1: # i.e. Series

0 commit comments

Comments
 (0)