how I can count the number of positive value in each column?
col1 col2 col3
5 6 7
-4 -8 7
1 -4 5
-4 -2 -1
output:
positives
3
1
2
0
I found the following way:
1- make it true , false
2-convert true ,false to 1 ,0
3-count 1s
sum3=average_monthly_trend.select(average_monthly_trend['col1']>0,average_monthly_trend['col2']>0,average_monthly_trend['col31']>0)
display(sum3.select([col(c).cast("integer") for c in sum3.columns]).withColumn('sum',sum(F.col(x) for x in sum3.columns)))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments