为了检查大熊猫是否包含缺失/ nan值,可以使用isnull函数。
test_pandas = pd.DataFrame([[np.float(3),np.float(1),np.float(4.3)],[np.float(5.8),np.nan,[1,2,3]]],columns = ['A','B','C'])
value = test_pandas.isnull().values.any()
test_pandas.head()
给予
A B C
0 3.0 1.0 4.3
1 5.8 NaN [1, 2, 3]
和
print("There exists a nan value in the dataframe: ",test_pandas.isnull().values.any())
print("Number of nan values: ",test_pandas.isnull().sum().sum())
我们找到
There exists a nan value in the dataframe: True
Number of nan values: 1
答案 0 :(得分:3)
您可以将自定义函数与applymap一起使用:
def isfloat(x):
return isinstance(x, float)
print(df.applymap(isfloat))
输出
A B C
0 True True True
1 True True False