Skip to content

Commit 0ed4549

Browse files
committed
DOC: add scalar results for timedeltas docs to timeseries.rst
1 parent 5c3fdc3 commit 0ed4549

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

doc/source/timeseries.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,27 @@ They can be both positive and negative.
943943
s - datetime(2011,1,1,3,5)
944944
s + timedelta(minutes=5)
945945
946+
Getting scalar results from a ``timedelta64[ns]`` series
947+
948+
.. ipython:: python
949+
950+
y = s - s[0]
951+
y
952+
y.apply(lambda x: x.item().total_seconds())
953+
y.apply(lambda x: x.item().days)
954+
955+
.. note::
956+
957+
These operations are different in numpy 1.6.2 and in numpy >= 1.7. The ``timedelta64[ns]`` scalar
958+
type in 1.6.2 is much like a ``datetime.timedelta``, while in 1.7 it is a nanosecond based integer.
959+
A future version of pandas will make this transparent.
960+
961+
These are the equivalent operation to above in numpy >= 1.7
962+
963+
``y.apply(lambda x: x.item()/np.timedelta64(1,'s'))``
964+
965+
``y.apply(lambda x: x.item()/np.timedelta64(1,'D'))``
966+
946967
Series of timedeltas with ``NaT`` values are supported
947968

948969
.. ipython:: python

0 commit comments

Comments
 (0)