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

问题描述 投票:2回答:1

我想在其中一列中删除所有NaN变量,但是当我使用 df.dropna(axis=0, inplace=True) 它删除了我的整个数据框架。为什么会发生这种情况?

我已经使用了两个 df.dropnadf.dropna(axis=0, inplace=True) 而且删除NaN也不行。

我正在对我的数据进行分选,这样我就可以运行一个高斯模型,但我不能对NaN变量进行分选,我想删除它们,但仍有我的数据框架来运行模型。

之前和之后Data

enter image description here

python pandas nan gaussian naivebayes
1个回答
0
投票

不知道你的情况如何,但分享一下在我的情况下有效的解决方案。

那些没有用的

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.

奏效的是:

df.dropna(how='all',axis=0, inplace=True) #==> Worked very well...

感谢上面Anky的评论

© www.soinside.com 2019 - 2024. All rights reserved.