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:ย 

column wise sum in PySpark dataframe

siddhu308
New Contributor II

i have a dataframe of 18000000rows and 1322 column with '0' and '1' value.

want to find how many '1's are in every column ???

below is DataSet

se_00001 se_00007 se_00036 se_00100 se_0010p se_00250

2 REPLIES 2

siddhu308
New Contributor II

seag_00001 seag_00007 seag_00036 seag_00100 seag_0010p seag_00250

1 0 1 0 0 0

mathan_pillai
Databricks Employee
Databricks Employee

Hi Siddhu,

You can use


df.select(sum("col1"), sum("col2"), sum("col3"))
where col1, col2, col3 are the column names for which you would like to find the sum

please let us know if it answers your question

Thanks

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