简体   繁体   English

在 pandas.Dataframe 中查找 NaN

[英]Find NaN's in pandas.Dataframe

This is my code to check if a certain cell in my Dataframe is empty.这是我的代码,用于检查数据框中的某个单元格是否为空。 Bfore there is a for loop to iterate over the rows.在有一个 for 循环来遍历行之前。 the counter is i计数器是i

if change.isna(change.iloc[i,3]):
         continue

Can't figure out why I receive the不明白为什么我收到

**TypeError**: isna() takes 1 positional argument but 2 were given

Because I just pass one argument.... Or am I wrong?因为我只是通过了一个论点......还是我错了?

The positional argument isna takes is self , because you're calling the method of pd.Dataframe ( change.isna() ). isna采用的位置参数是self ,因为您正在调用pd.Dataframe ( change.isna() ) 的方法。 You're passing one argument, but that's the second argument to the function, hence the error.您正在传递一个参数,但这是该函数的第二个参数,因此出现错误。

Take a look at pd.Dataframe.isna 's documentation : there is only self specified as argument.看看pd.Dataframe.isna的文档:只有self指定为参数。 This is, because isna actually returns a boolean array where for each element in the dataframe it tells you whether it's a valid value or NA.这是因为isna实际上返回一个布尔数组,其中对于数据框中的每个元素,它会告诉您它是有效值还是 NA。

if change.iloc[i].isna()[3]:
  ....

Alternatively, use the function pandas.isna() , which takes exactly one object as argument:或者,使用函数pandas.isna()pandas.isna()接受一个对象作为参数:

if pd.isna(change.iloc[i,3]):
  ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM