[英]How to filter missing data rows using python
I have a dataframe df
and one of the features called mort_acc
have missing data.我有一个 dataframe df
,其中一个名为mort_acc
的功能缺少数据。 I want to filter out those rows that contains missing data for mort_acc
and I used the following way我想过滤掉那些包含mort_acc
缺失数据的行,我使用了以下方式
df[df['mort_acc'].apply(lambda x:x == " ")]
It didn't work.它没有用。 I got output 0
.我得到了 output 0
。 So I used the following lambda way所以我用了下面的lambda方式
df[df['mort_acc'].apply(lambda x:len(x)<0)]
It didn't work too and this time got error object of type 'float' has no len()
它也没有工作,这次出现错误object of type 'float' has no len()
So I tried this way所以我尝试了这种方式
df[df['mort_acc'].apply(lambda x:x == NaN)]
Error happened again name 'NaN' is not defined
再次发生错误name 'NaN' is not defined
Does anyone know how to do it?有谁知道该怎么做?
bad_values_row_mask = df['mort_acc'].isna()
df[bad_values_row_mask]
sounds like what you want I guess听起来像你想要的,我猜
there is no datatype as NaN in python use pd.isna() to check if it's nan. python 中没有数据类型为 NaN,使用 pd.isna() 检查它是否为 nan。
df[df['mort_acc'].apply(lambda x:pd.isna(x))]
This will give you rows where the column value is having NaN values.这将为您提供列值具有 NaN 值的行。
df[df.mort_acc.isnull()]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.