我有 pandas 数据框 df
,我想打印出变量列表以及类型和缺失字段的数量(NaN、NA)。
def var_desc(df,dt):
print('============================================')
for c in df.columns:
if df[c].dtype==dt:
e = sum(pd.isnull(df[c]))
print(c+' : '+dt+' | '+e)
print('============================================')
var_desc(df,"object")
var_desc(df,"int64")
行 e = sum(pd.isnull(df[c]))
存在一些问题。它给出以下错误:
TypeError: ufunc 'add' 不包含签名匹配类型 dtype('S23') dtype('S23') dtype('S23') 的循环
如何解决?
最佳答案
你可以使用
count_nan = len(df) - df.count()
如count返回非 NA/null,这样您就可以达到非 None 记录的数量。
DataFrame.count(axis=0, level=None, numeric_only=False)[source]¶
Return Series with number of non-NA/null observations over requested axis. Works with non-floating point data as well (detects NaN and None)
关于python - 类型错误 : ufunc 'add' did not contain a loop with signature matching types dtype ('S23' ) dtype ('S23' ) dtype ('S23' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43784832/