- API reference
- Series
- pandas.Serie...
pandas.Series.dt.to_pydatetime#
- Series.dt.to_pydatetime()[source]#
Return the data as an array of
datetime.datetime
objects.Deprecated since version 2.1.0:The current behavior of dt.to_pydatetime is deprecated.In a future version this will return a Series containing pythondatetime objects instead of a ndarray.
Timezone information is retained if present.
Warning
Python’s datetime uses microsecond resolution, which is lower thanpandas (nanosecond). The values are truncated.
- Returns:
- numpy.ndarray
Object dtype array containing native Python datetime objects.
See also
datetime.datetime
Standard library value for a datetime.
Examples
>>>s=pd.Series(pd.date_range('20180310',periods=2))>>>s0 2018-03-101 2018-03-11dtype: datetime64[ns]
>>>s.dt.to_pydatetime()array([datetime.datetime(2018, 3, 10, 0, 0), datetime.datetime(2018, 3, 11, 0, 0)], dtype=object)
pandas’ nanosecond precision is truncated to microseconds.
>>>s=pd.Series(pd.date_range('20180310',periods=2,freq='ns'))>>>s0 2018-03-10 00:00:00.0000000001 2018-03-10 00:00:00.000000001dtype: datetime64[ns]
>>>s.dt.to_pydatetime()array([datetime.datetime(2018, 3, 10, 0, 0), datetime.datetime(2018, 3, 10, 0, 0)], dtype=object)
On this page