I have a pandas dataframe that looks lie:
A
3 days
NaT
4 days
Is there a way to replace the NaT with 0 days ?
thanks, Ed
replace({pd. NaT: None}, inplace=True) .
NaN doesn't equal NaN . And NaT doesn't equal NaT . But None does equal None .
Datetimes. For datetime64[ns] types, NaT represents missing values. This is a pseudo-native sentinel value that can be represented by NumPy in a singular dtype (datetime64[ns]). pandas objects provide compatibility between NaT and NaN .
Please note that the other answers are not up to date anymore. The preferred syntax is:
df['column'].fillna(pd.Timedelta(seconds=0))
The previously mentioned
df['column'].fillna(0)
will results in:
FutureWarning: Passing integers to fillna is deprecated, will raise a TypeError in a future version. To retain the old behavior, pass pd.Timedelta(seconds=n) instead. df['column'] = df['column'].fillna(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With