how to check the particular column value in spark dataframe ?

databicky
Contributor II

if i want​ to check the the particular column in dataframe is need to contain zero, if its not have zero means , it need to get fail

MateuszLomanski
New Contributor II

use the agg method to check if the count of rows where columnName contains 0, is equal to the total number of rows in the dataframe, using the following code: df.agg(count("*").alias("total_count"),count(when(col("columnName")===0,1)).alias("zero_count")).filter("total_count == zero_count").count()

This will return 1 if all the rows contain 0 in the columnName and 0 otherwise

no it doesn't worked, actually what i want is have one column in spark dataframe as count, for that particular column value is greater than 0 means, it needs to exit.

but the above answer is totally different​