how I can count the number of positive value in each column?

user15649753

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
user15649753

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.

edited at
0

Comments

0 comments
Login to comment

Related

How can I do count on number of occurrences of each distinct value of a column in PostgreSQL?

How can I count the number of posts that have either zero or positive vote score?

How can I count the number of relationships each node has in Cypher?

How can I group by the count number of column values and sort it?

Python Pandas: How can I count the number of times a value appears in a column based upon another column?

How to count the number of times a value occurs in each column (per column), using Pandas?

How can I count if column value is equal to NaN or zero?

How can I compare 2 CSV files, check if the values of the second column match and count the number of occurrences for each value when they match?

How can I count the number of columns a value has after a Where?

How to count number of rows with NA on each column?

How can I obtain a random number for each column in a matrix?

SQL How can I count the number of meetings for each client?

How can I get the count of consecutive positive number in each column in 2 dimensional df in python/ Padas

How can I count the number of

How can I count features in each column of my dataframe ?

How can I filter a table to return only an equal number of rows based on a positive and negative value?

How can I count the number of messages in one channel of each user?

Count the number of times each value appears in a column

How Can I count the number of Capital Cities within each Continent?

How can I count number of appearance of a value and make it into a new column when querying?

Power BI - how can i count the occurrences of a value in a column?

How can I count the number of floats or integers in a column of a Pandas dataframe?

For each value in a column, how to count the number of unique values in its row?

How can I change the number of int value to another number in a column?

How can I make a function that adds a number to each value in an array?

How can I count values for each date in a Dataframe based conditionally on the value of a column?

How do I count the number of occurrences of a string in a column in each file, and output the result filename and count + awk

How can I count the number of rectangular in column?

r: Count number of each value in every column