@@ -20,16 +20,16 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
20
20
"""
21
21
Convert argument to timedelta.
22
22
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
25
25
from a recognized timedelta format / value into a Timedelta type.
26
26
27
27
Parameters
28
28
----------
29
29
arg : String, timedelta, list, tuple, 1-d array, or Series
30
30
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.
33
33
box : Boolean, default True
34
34
If True returns a Timedelta/TimedeltaIndex of the results.
35
35
if False returns a np.timedelta64 or ndarray of values of dtype
@@ -69,8 +69,6 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
69
69
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
70
70
dtype='timedelta64[ns]', freq=None)
71
71
72
- For `M` and `Y` units, `1M = 30D` and 1Y = 365D:
73
-
74
72
>>> pd.to_timedelta(np.arange(5), unit='M')
75
73
TimedeltaIndex([ '0 days 00:00:00', '30 days 10:29:06',
76
74
'60 days 20:58:12', '91 days 07:27:18',
@@ -82,8 +80,13 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
82
80
'1460 days 23:16:48'],
83
81
dtype='timedelta64[ns]', freq=None)
84
82
83
+ Returning an ndarray by using the 'box' keyword argument:
84
+
85
+ >>> pd.to_timedelta(np.arange(5), box=False)
86
+ array([0, 1, 2, 3, 4], dtype='timedelta64[ns]')
87
+
85
88
Add new column of dates from existing dates in a `DataFrame`
86
- using `timedelta`
89
+ using `timedelta`:
87
90
88
91
>>> Dates = pd.to_datetime(['26/10/2018','28/10/2018', '2/11/2018'])
89
92
>>> df = pd.DataFrame({'Start': Dates,'Days':[5, 10, 5]})
0 commit comments