检查单个单元格的值是否为Pandas中的NaN

问题描述:

我只想检查Pandas系列中的单个单元格是否为空,即检查值是否为NaN.

I just want to check if a single cell in Pandas series is null or not i.e. to check if a value is NaN.

所有其他答案适用于序列和数组,但不适用于单个值.

All other answers are for series and arrays, but not for single value.

我尝试了pandas.notnullpandas.isnullnumpy.isnan.是否只有一个单一值的解决方案?

I have tried pandas.notnull, pandas.isnull, numpy.isnan. Is there a solution for a single value only?

尝试一下:

import pandas as pd
import numpy as np
from pandas import *

>>> L = [4, nan ,6]
>>> df = Series(L)

>>> df
0     4
1   NaN
2     6

>>> if(pd.isnull(df[1])):
        print "Found"

Found

>>> if(np.isnan(df[1])):
        print "Found"

Found