检查数据框是否包含任何空值 [英] Check whether dataframe contains any null values

查看:251
本文介绍了检查数据框是否包含任何空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,需要查看它是否包含空值。关于同一主题的文章很多,但几乎所有文章都使用 count 操作或 show 方法。

I have a dataframe and need to see if it contains null values. There are plenty of posts on the same topic but nearly all of them use the count action or the show method.

count 操作对于我来说是非常昂贵的,因为数据量很大。与 show 方法相同。

count operations are prohibitively expensive in my case as the data volume is large. Same for the show method.

有没有一种方法可以让spark查找空值,并且遇到第一个空值时立即引发错误?

Is there a way in which I can ask spark to look for null values and raise an error as soon as it encounters the first null value?

其他帖子中的解决方案给出了每列中缺失值的计数。我不需要知道每一列中缺失值的数量。
我只想知道数据框中是否有一个值为空的单元格。

The solutions in other posts give the count of missing values in each column. I don't need to know the number of missing values in every column. I just want to know if there is any cell in the dataframe with a null value.

推荐答案

您可以使用限制

df.select("*").where(col("c").isNull()).limit(1)

这篇关于检查数据框是否包含任何空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆