Nan 在 Python 中没有辍学 [英] Nan does not drop out in Python

查看:48
本文介绍了Nan 在 Python 中没有辍学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,如下所示:

I have a dataframe which is shown below:

我想删除Rego"列中包含 nan 的所有记录.我尝试了一些命令,例如

I want to drop out all the record that has nan in 'Rego' column. I tried few commands such as

temp_df = temp_df[temp_df['Rego'].notnull()]
temp_df = temp_df[temp_df['Rego'].notna()]
t = temp_df.loc[temp_df['Rego'].notnull()]
temp_df.dropna(axis=0,how='all')
temp_df.dropna(how ='any',inplace=True)

但上述命令都不会从 Rego 列中删除 nan 值.我查看了论坛的现有线程(Can't drop NAN with dropna in pandas) 但无法解决问题.谁能指导我哪里出错了?

but none of the above commands drop nan values from the Rego column. I looked into existing threads of the forum (Can't drop NAN with dropna in pandas) but couldn't fix the issue. Could anyone guide me where am I making the mistake?

推荐答案

也许一些 nan 值是一个 str,所以先这样做:

Maybe some nan value is a str, so do this first:

temp_df['Rego'].replace('nan',np.nan,inplace=True)

那么现在你可以:

temp_df_fitered=temp_df[temp_df['Rego'].notnull()]

这篇关于Nan 在 Python 中没有辍学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆