@@ -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,21 +69,13 @@ 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 :
72
+ Returning an ndarray by using the 'box' keyword argument :
73
73
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]')
84
76
85
77
Add new column of dates from existing dates in a `DataFrame`
86
- using `timedelta`
78
+ using `timedelta`:
87
79
88
80
>>> Dates = pd.to_datetime(['26/10/2018','28/10/2018', '2/11/2018'])
89
81
>>> df = pd.DataFrame({'Start': Dates,'Days':[5, 10, 5]})
0 commit comments