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

3 REPLIES 3

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

Kaniz_Fatma
Community Manager
Community Manager

Hi @Mohammed sadamuseanโ€‹  (Customer)โ€‹, We havenโ€™t heard from you since the last response from @Mateusz ลomaล„skiโ€‹ (Customer)โ€‹ , and I was checking back to see if his suggestions helped you.

Or else, If you have any solution, please share it with the community, as it can be helpful to others.

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

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โ€‹

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group