pandas.Series.dt.to_pydatetime#

Series.dt.to_pydatetime()[source] #

Return the data as a Series of datetime.datetime objects.

Timezone information is retained if present.

Warning

Python’s datetime uses microsecond resolution, which is lower than pandas (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))
>>> s
0 2018年03月10日
1 2018年03月11日
dtype: datetime64[ns]
>>> s.dt.to_pydatetime()
0 2018年03月10日 00:00:00
1 2018年03月11日 00:00:00
dtype: object

pandas’ nanosecond precision is truncated to microseconds.

>>> s = pd.Series(pd.date_range("20180310", periods=2, freq="ns"))
>>> s
0 2018年03月10日 00:00:00.000000000
1 2018年03月10日 00:00:00.000000001
dtype: datetime64[ns]
>>> s.dt.to_pydatetime()
0 2018年03月10日 00:00:00
1 2018年03月10日 00:00:00
dtype: object

This Page