'how I can count the number of positive value in each column?
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
Solution 1:[1]
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)))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
