Skip to content

Commit 789e07d

Browse files
committed
DOC: clean up timeseries.rst a bit
1 parent 76a4d99 commit 789e07d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

doc/source/timeseries.rst

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,33 +1757,39 @@ TZ aware Dtypes
17571757

17581758
.. ipython:: python
17591759
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))
17631761
s_naive
17641762
17651763
``Series/DatetimeIndex`` with a timezone **aware** value are represented with a dtype of ``datetime64[ns, tz]``.
17661764

17671765
.. ipython:: python
17681766
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'))
17721768
s_aware
17731769
17741770
Both of these ``Series`` can be manipulated via the ``.dt`` accessor, see :ref:`here <basics.dt_accessors>`.
17751771
See the :ref:`docs <timeseries.dtypes>` for more details.
17761772

1777-
Further more you can ``.astype(...)`` timezone aware (and naive).
1773+
For example, to localize and convert a naive stamp to timezone aware.
17781774

17791775
.. ipython:: python
17801776
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
17821789
s_aware.astype('datetime64[ns]')
17831790
1784-
# convert
1791+
# convert to a new timezone
17851792
s_aware.astype('datetime64[ns, CET]')
1786-
s_naive.astype('datetime64[ns, CET]')
17871793
17881794
.. note::
17891795

@@ -1805,4 +1811,4 @@ Further more you can ``.astype(...)`` timezone aware (and naive).
18051811

18061812
.. ipython:: python
18071813
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

Comments
 (0)