@@ -18,8 +18,8 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
18
18
"""
19
19
Convert argument to timedelta.
20
20
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
23
23
from a recognized timedelta format / value into a Timedelta type.
24
24
25
25
Parameters
@@ -76,21 +76,13 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
76
76
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
77
77
dtype='timedelta64[ns]', freq=None)
78
78
79
- For `M` and `Y` units, `1M = 30D` and 1Y = 365D :
79
+ Returning an ndarray by using the 'box' keyword argument :
80
80
81
- >>> pd.to_timedelta(np.arange(5), unit='M')
82
- TimedeltaIndex([ '0 days 00:00:00', '30 days 10:29:06',
83
- '60 days 20:58:12', '91 days 07:27:18',
84
- '121 days 17:56:24'],
85
- dtype='timedelta64[ns]', freq=None)
86
- >>> pd.to_timedelta(np.arange(5), unit='Y')
87
- TimedeltaIndex([ '0 days 00:00:00', '365 days 05:49:12',
88
- '730 days 11:38:24', '1095 days 17:27:36',
89
- '1460 days 23:16:48'],
90
- dtype='timedelta64[ns]', freq=None)
81
+ >>> pd.to_timedelta(np.arange(5), box=False)
82
+ array([0, 1, 2, 3, 4], dtype='timedelta64[ns]')
91
83
92
84
Add new column of dates from existing dates in a `DataFrame`
93
- using `timedelta`
85
+ using `timedelta`:
94
86
95
87
>>> Dates = pd.to_datetime(['26/10/2018','28/10/2018', '2/11/2018'])
96
88
>>> df = pd.DataFrame({'Start': Dates,'Days':[5, 10, 5]})
0 commit comments