@@ -56,6 +56,10 @@ You can construct a ``Timedelta`` scalar thru various arguments:
56
56
Timedelta(timedelta(days = 1 ,seconds = 1 ))
57
57
Timedelta(np.timedelta64(1 ,' ms' ))
58
58
59
+ # negative Timedeltas have this string repr
60
+ # to be more consistent with datetime.timedelta conventions
61
+ Timedelta(' -1us' )
62
+
59
63
# a NaT
60
64
Timedelta(' nan' )
61
65
Timedelta(' nat' )
@@ -160,7 +164,7 @@ Operands can also appear in a reversed order (a singular object operated with a
160
164
df.idxmin()
161
165
df.idxmax()
162
166
163
- ``min, max, idxmin, idxmax `` operations are supported on Series / DataFrames . A single result will be a ``Timedelta ``.
167
+ ``min, max, idxmin, idxmax `` operations are supported on Series as well . A scalar result will be a ``Timedelta ``.
164
168
165
169
.. ipython :: python
166
170
@@ -184,6 +188,7 @@ You can also negate, multiply and use ``abs`` on ``Timedeltas``
184
188
.. ipython :: python
185
189
186
190
td1 = Timedelta(' -1 days 2 hours 3 seconds' )
191
+ tdi
187
192
- 1 * td1
188
193
- td1
189
194
abs (td1)
@@ -193,14 +198,17 @@ You can also negate, multiply and use ``abs`` on ``Timedeltas``
193
198
Reductions
194
199
----------
195
200
196
- Numeric reduction operation for ``timedelta64[ns] `` will return ``Timedelta `` objects.
201
+ Numeric reduction operation for ``timedelta64[ns] `` will return ``Timedelta `` objects. As usual
202
+ ``NaT `` are skipped during evaluation.
197
203
198
204
.. ipython :: python
199
205
200
- y2 = y.fillna(timedelta( days = - 1 , seconds = 5 ))
206
+ y2 = Series(to_timedelta([ ' -1 days +00:00:05 ' , ' nat ' , ' -1 days +00:00:05 ' , ' 1 days ' ] ))
201
207
y2
202
208
y2.mean()
209
+ y2.median()
203
210
y2.quantile(.1 )
211
+ y2.sum()
204
212
205
213
.. _timedeltas.timedeltas_convert :
206
214
@@ -336,6 +344,9 @@ Furthermore you can use partial string selection and the range will be inferred:
336
344
337
345
s[' 1 day' :' 1 day 5 hours' ]
338
346
347
+ Operations
348
+ ~~~~~~~~~~
349
+
339
350
Finally, the combination of ``TimedeltaIndex `` with ``DatetimeIndex `` allow certain combination operations that are NaT preserving:
340
351
341
352
.. ipython :: python
@@ -347,18 +358,32 @@ Finally, the combination of ``TimedeltaIndex`` with ``DatetimeIndex`` allow cert
347
358
(dti + tdi).tolist()
348
359
(dti - tdi).tolist()
349
360
361
+ Conversions
362
+ ~~~~~~~~~~~
363
+
350
364
Similarly to frequency conversion on a ``Series `` above, you can convert these indices to yield another Index.
351
365
352
366
.. ipython :: python
353
367
354
368
tdi / np.timedelta64(1 ,' s' )
355
369
tdi.astype(' timedelta64[s]' )
356
370
357
- Scalars type ops work as well
371
+ Scalars type ops work as well. These can potentially return a * different * type of index.
358
372
359
373
.. ipython :: python
360
374
375
+ # adding or timedelta and date -> datelike
361
376
tdi + Timestamp(' 20130101' )
362
- tdi + Timedelta(' 10 days' )
377
+
378
+ # subtraction of a date and a timedelta -> datelike
379
+ # note that trying to subtract a date from a Timedelta will raise an exception
363
380
(Timestamp(' 20130101' ) - tdi).tolist()
381
+
382
+ # timedelta + timedelta -> timedelta
383
+ tdi + Timedelta(' 10 days' )
384
+
385
+ # division can result in a Timedelta if the divisor is an integer
386
+ tdi / 2
387
+
388
+ # or a Float64Index if the divisor is a Timedelta
364
389
tdi / tdi[0 ]
0 commit comments