Problem: dropna() method is returning NaN values

六月ゝ 毕业季﹏ 提交于 2021-02-10 18:47:57

问题


Having problems with the .dropna() method. I have created a new variable energy_c which is a copy of energy but with mont being more or equal to 0.1.

I then took out the columns with nothing in after printing them and then am trying to drop all rows that have NaN values in the remaining columns. However my output is returning NaN values even after using .dropna().

energy_c = energy.loc[energy.loc[:, 'mont'] >= 0.1].copy()
energy_c.columns[energy.isna().all()].tolist()
drop_cols = energy_c.loc[:,['EndDate', 'Ref', 'dis']]
energy_c.drop(drop_cols, axis=1, inplace=True)
energy_c.dropna()
print(energy_c)

Could someone advise as to what I have done wrong?

Thanks.


回答1:


dropna is not an inplace method, try energy_c = energy_c.dropna().




回答2:


Try

energy_c.dropna(inplace = True)

This does the operation inplace and returns None, according to the documentation.



来源:https://stackoverflow.com/questions/53322643/problem-dropna-method-is-returning-nan-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!