@@ -1757,33 +1757,39 @@ TZ aware Dtypes
1757
1757
1758
1758
.. ipython :: python
1759
1759
1760
- dr_naive = pd.date_range(' 20130101' ,periods = 3 )
1761
- dr_naive
1762
- s_naive = Series(dr_naive)
1760
+ s_naive = pd.Series(pd.date_range(' 20130101' ,periods = 3 ))
1763
1761
s_naive
1764
1762
1765
1763
``Series/DatetimeIndex `` with a timezone **aware ** value are represented with a dtype of ``datetime64[ns, tz] ``.
1766
1764
1767
1765
.. ipython :: python
1768
1766
1769
- dr_aware = pd.date_range(' 20130101' ,periods = 3 ,tz = ' US/Eastern' )
1770
- dr_aware
1771
- s_aware = Series(dr_aware)
1767
+ s_aware = pd.Series(pd.date_range(' 20130101' ,periods = 3 ,tz = ' US/Eastern' ))
1772
1768
s_aware
1773
1769
1774
1770
Both of these ``Series `` can be manipulated via the ``.dt `` accessor, see :ref: `here <basics.dt_accessors >`.
1775
1771
See the :ref: `docs <timeseries.dtypes >` for more details.
1776
1772
1777
- Further more you can `` .astype(...) `` timezone aware (and naive) .
1773
+ For example, to localize and convert a naive stamp to timezone aware .
1778
1774
1779
1775
.. ipython :: python
1780
1776
1781
- # make this naive
1777
+ s_naive.dt.tz_localize(' UTC' ).dt.tz_convert(' US/Eastern' )
1778
+
1779
+
1780
+ Further more you can ``.astype(...) `` timezone aware (and naive). This operation is effectively a localize AND convert on a naive stamp, and
1781
+ a convert on an aware stamp.
1782
+
1783
+ .. ipython :: python
1784
+
1785
+ # localize and convert a naive timezone
1786
+ s_naive.astype(' datetime64[ns, US/Eastern]' )
1787
+
1788
+ # make an aware tz naive
1782
1789
s_aware.astype(' datetime64[ns]' )
1783
1790
1784
- # convert
1791
+ # convert to a new timezone
1785
1792
s_aware.astype(' datetime64[ns, CET]' )
1786
- s_naive.astype(' datetime64[ns, CET]' )
1787
1793
1788
1794
.. note ::
1789
1795
@@ -1805,4 +1811,4 @@ Further more you can ``.astype(...)`` timezone aware (and naive).
1805
1811
1806
1812
.. ipython :: python
1807
1813
1808
- Series(s_aware).dt.tz_localize(' UTC' ).dt.tz_convert(' US/Eastern' )
1814
+ pd. Series(s_aware.values ).dt.tz_localize(' UTC' ).dt.tz_convert(' US/Eastern' )
0 commit comments