so this should work for timedeltas AND datetimes.
Should be straight forward. detect an i8 convertible. turn into i8. do the cut. turn back to the original dtype.
In [15]: s = Series(pd.to_timedelta(np.random.randint(0,100,size=10),unit='ms')).sort_values()
In [16]: s
Out[16]:
3 00:00:00.005000
5 00:00:00.007000
7 00:00:00.010000
4 00:00:00.017000
9 00:00:00.023000
1 00:00:00.043000
0 00:00:00.045000
6 00:00:00.047000
8 00:00:00.065000
2 00:00:00.090000
dtype: timedelta64[ns]
In [18]: pd.cut(s, 5)
TypeError: unsupported operand type(s) for +: 'Timedelta' and 'float'
# works when converted
In [17]: pd.cut(s.astype('timedelta64[ms]'), 5)
Out[17]:
3 (4.915, 22]
5 (4.915, 22]
7 (4.915, 22]
4 (4.915, 22]
9 (22, 39]
1 (39, 56]
0 (39, 56]
6 (39, 56]
8 (56, 73]
2 (73, 90]
dtype: category
Categories (5, object): [(4.915, 22] < (22, 39] < (39, 56] < (56, 73] < (73, 90]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4