Sourav Roy
Sourav Roy

Reputation: 417

How to replace Nan from column with float data in a data frame in python

I am trying to replace NAN from a dataframe column which is of float type.

> for i in range(len(tdf)):
>     if tdf['Counterfeit_Weight'][i] =='NaN': # also have tried with np.NaN
>         tdf.loc[i,"Counterfeit_Weight"]=p

I tried np.where, imputer class but nothing is working.

tdf.isnull().sum()
Medicine_ID               0
Counterfeit_Weight     1166
DistArea_ID               0
Active_Since              0  

Plz Help

Upvotes: 0

Views: 983

Answers (1)

Ashish
Ashish

Reputation: 739

Following one line should work for you

tdf['Counterfeit_Weight'].fillna(p)

Upvotes: 1

Related Questions