Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing NaT with 0 days

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

like image 743
Number Logic Avatar asked Mar 12 '18 17:03

Number Logic


People also ask

How do you change NaT to blank in Python?

replace({pd. NaT: None}, inplace=True) .

Is NaT same as NaN?

NaN doesn't equal NaN . And NaT doesn't equal NaT . But None does equal None .

What is NaT panda?

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 .


1 Answers

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)

like image 149
Simon Avatar answered Sep 28 '22 05:09

Simon