cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

2 REPLIES 2

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​

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now