如何在python中用数据帧中的浮点数据替换列中的Nan

如何在python中用数据帧中的浮点数据替换列中的Nan,python,pandas,nan,Python,Pandas,Nan,我试图从一个浮点型的数据帧列中替换NAN > for i in range(len(tdf)): > if tdf['Counterfeit_Weight'][i] =='NaN': # also have tried with np.NaN > tdf.loc[i,"Counterfeit_Weight"]=p 我尝试了np.where,插补类,但没有任何效果 tdf.isnull().sum() Medicine_ID

我试图从一个浮点型的数据帧列中替换NAN

> for i in range(len(tdf)):
>     if tdf['Counterfeit_Weight'][i] =='NaN': # also have tried with np.NaN
>         tdf.loc[i,"Counterfeit_Weight"]=p
我尝试了np.where,插补类,但没有任何效果

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

Plz帮助

下面的一行应该适合您

tdf['Counterfeit_Weight'].fillna(p)

与我们共享您的数据,例如df.head().to_dict()。Nan通常由fillna代替: