Skip to content

Commit 88ff298

Browse files
committed
Added box example and removed M and Y unit references
1 parent e34d2ac commit 88ff298

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

pandas/core/tools/timedeltas.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
2020
"""
2121
Convert argument to timedelta.
2222
23-
Timedeltas are differences in times, expressed in difference units
24-
e.g. days, hours, minutes, seconds. This method converts an argument
23+
Timedeltas are absolute differences in times, expressed in difference
24+
units e.g. days, hours, minutes, seconds. This method converts an argument
2525
from a recognized timedelta format / value into a Timedelta type.
2626
2727
Parameters
2828
----------
2929
arg : String, timedelta, list, tuple, 1-d array, or Series
3030
The argument which needs to be converted to timedelta.
31-
unit : Integer or float
32-
Denotes the unit (Y,M,D,h,m,s,ms,us,ns) of the arg.
31+
unit : Integer or float, default ns
32+
Denotes the unit (D,h,m,s,ms,us,ns) of the arg.
3333
box : Boolean, default True
3434
If True returns a Timedelta/TimedeltaIndex of the results.
3535
if False returns a np.timedelta64 or ndarray of values of dtype
@@ -69,21 +69,13 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
6969
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
7070
dtype='timedelta64[ns]', freq=None)
7171
72-
For `M` and `Y` units, `1M = 30D` and 1Y = 365D:
72+
Returning an ndarray by using the 'box' keyword argument:
7373
74-
>>> pd.to_timedelta(np.arange(5), unit='M')
75-
TimedeltaIndex([ '0 days 00:00:00', '30 days 10:29:06',
76-
'60 days 20:58:12', '91 days 07:27:18',
77-
'121 days 17:56:24'],
78-
dtype='timedelta64[ns]', freq=None)
79-
>>> pd.to_timedelta(np.arange(5), unit='Y')
80-
TimedeltaIndex([ '0 days 00:00:00', '365 days 05:49:12',
81-
'730 days 11:38:24', '1095 days 17:27:36',
82-
'1460 days 23:16:48'],
83-
dtype='timedelta64[ns]', freq=None)
74+
>>> pd.to_timedelta(np.arange(5), box=False)
75+
array([0, 1, 2, 3, 4], dtype='timedelta64[ns]')
8476
8577
Add new column of dates from existing dates in a `DataFrame`
86-
using `timedelta`
78+
using `timedelta`:
8779
8880
>>> Dates = pd.to_datetime(['26/10/2018','28/10/2018', '2/11/2018'])
8981
>>> df = pd.DataFrame({'Start': Dates,'Days':[5, 10, 5]})

0 commit comments

Comments
 (0)