我知道我可以在 Polars 中执行
.null_count()
,它会返回一个数据帧,告诉我每列的空计数。
d = {"foo":[1,2,3, None], "bar":[4,None, None, 6]}
df_polars_withnull = pl.from_dict(d)
df_polars_withnull.null_count()
会产生一个数据框
foo bar
1 2
我想知道整个数据框中是否有任何空值
类似的东西
if any(df_polars_withnull.null_count()):
print ('has nulls')
else:
print ('no nulls')
不幸的是,这不起作用。这里正确的代码是什么?
这可行,但看起来有点难看
if df_polars_nonull.null_count().sum(axis=1)[0]:
print ('has nulls')
else:
print ('no nulls')