Series.dt.to_pytimedelta() numpy.ndarray

Return an array of native datetime.timedelta objects.

Python’s standard datetime library uses a different representation timedelta’s. This method converts a Series of pandas Timedeltas to datetime.timedelta format with the same length as the original Series.


Array of 1D containing data with datetime.timedelta type.

Return type


See also


A duration expressing the difference between two date, time, or datetime.


>>> import mars.tensor as mt
>>> import mars.dataframe as md
>>> s = md.Series(md.to_timedelta(mt.arange(5), unit="d"))
>>> s.execute()
0   0 days
1   1 days
2   2 days
3   3 days
4   4 days
dtype: timedelta64[ns]
>>> s.dt.to_pytimedelta().execute()
array([datetime.timedelta(0), datetime.timedelta(days=1),
datetime.timedelta(days=2), datetime.timedelta(days=3),
datetime.timedelta(days=4)], dtype=object)