Skip to content

Commit f10dbd3

Browse files
committed
Added box example and removed M and Y unit references
1 parent 8d6de9c commit f10dbd3

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

pandas/core/tools/timedeltas.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
1818
"""
1919
Convert argument to timedelta.
2020
21-
Timedeltas are differences in times, expressed in difference units
22-
e.g. days, hours, minutes, seconds. This method converts an argument
21+
Timedeltas are absolute differences in times, expressed in difference
22+
units e.g. days, hours, minutes, seconds. This method converts an argument
2323
from a recognized timedelta format / value into a Timedelta type.
2424
2525
Parameters
@@ -71,21 +71,13 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
7171
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
7272
dtype='timedelta64[ns]', freq=None)
7373
74-
For `M` and `Y` units, `1M = 30D` and 1Y = 365D:
74+
Returning an ndarray by using the 'box' keyword argument:
7575
76-
>>> pd.to_timedelta(np.arange(5), unit='M')
77-
TimedeltaIndex([ '0 days 00:00:00', '30 days 10:29:06',
78-
'60 days 20:58:12', '91 days 07:27:18',
79-
'121 days 17:56:24'],
80-
dtype='timedelta64[ns]', freq=None)
81-
>>> pd.to_timedelta(np.arange(5), unit='Y')
82-
TimedeltaIndex([ '0 days 00:00:00', '365 days 05:49:12',
83-
'730 days 11:38:24', '1095 days 17:27:36',
84-
'1460 days 23:16:48'],
85-
dtype='timedelta64[ns]', freq=None)
76+
>>> pd.to_timedelta(np.arange(5), box=False)
77+
array([0, 1, 2, 3, 4], dtype='timedelta64[ns]')
8678
8779
Add new column of dates from existing dates in a `DataFrame`
88-
using `timedelta`
80+
using `timedelta`:
8981
9082
>>> Dates = pd.to_datetime(['26/10/2018','28/10/2018', '2/11/2018'])
9183
>>> df = pd.DataFrame({'Start': Dates,'Days':[5, 10, 5]})

0 commit comments

Comments
 (0)