pandas.Timestamp.to_pydatetime — pandas 3.0.0rc0+52.gb43b95d2b4 documentation (original) (raw)
Timestamp.to_pydatetime(warn=True)#
Convert a Timestamp object to a native Python datetime object.
This method is useful for when you need to utilize a pandas Timestamp object in contexts where native Python datetime objects are expected or required. The conversion discards the nanoseconds component, and a warning can be issued in such cases if desired.
Parameters:
warnbool, default True
If True, issues a warning when the timestamp includes nonzero nanoseconds, as these will be discarded during the conversion.
Returns:
datetime.datetime or NaT
Returns a datetime.datetime object representing the timestamp, with year, month, day, hour, minute, second, and microsecond components. If the timestamp is NaT (Not a Time), returns NaT.
Examples
ts = pd.Timestamp('2020-03-14T15:32:52.192548') ts.to_pydatetime() datetime.datetime(2020, 3, 14, 15, 32, 52, 192548)
Analogous for pd.NaT:
pd.NaT.to_pydatetime() NaT