maxframe.dataframe.Series.dt.to_pydatetime#

Series.dt.to_pydatetime() Series#

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:

Object dtype array containing native Python datetime objects.

Return type:

numpy.ndarray

See also

datetime.datetime

Standard library value for a datetime.

Examples

>>> import maxframe.dataframe as md
>>> s = md.Series(md.date_range("20180310", periods=2))
>>> s.execute()
0   2018-03-10
1   2018-03-11
dtype: datetime64[us]
>>> s.dt.to_pydatetime().execute()
0    2018-03-10 00:00:00
1    2018-03-11 00:00:00
dtype: object

pandas’ nanosecond precision is truncated to microseconds.

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