python中的代码“df.dropna”擦除了我的整个数据框,我的代码有什么问题?

Pip*_*rez 6 python gaussian nan pandas naivebayes

我想删除其中一列中的所有 NaN 变量,但是当我使用df.dropna(axis=0, inplace=True)它时会删除我的整个数据帧。为什么会这样?

我已经使用了df.dropnaanddf.dropna(axis=0, inplace=True)并且它无法删除 NaN。

我正在对我的数据进行分箱,所以我可以运行一个高斯模型,但我不能用 NaN 变量来做到这一点,我想删除它们并且仍然有我的数据框来运行模型。

之前和之后 数据

在此处输入图片说明

小智 2

不确定您的案例,但分享适用于我的案例的解决方案:

那些不起作用的:

df = df.dropna() #==> make the df empty.
df = df.dropna(axis=0, inplace=True) #==> make the df empty.
df.dropna(axis=0, inplace=True) #==> make the df empty.
Run Code Online (Sandbox Code Playgroud)

有效的:

df.dropna(how='all',axis=0, inplace=True) #==> Worked very well...
Run Code Online (Sandbox Code Playgroud)

感谢上面 Anky 的评论。