-1

enter image description here

I need to count the number of fields that have a value > 0

I've tried a lot and i don't understand, why everything is so complicated and i can't just use countif or sumif like in the sql. Help me please

Corralien
  • 109,409
  • 8
  • 28
  • 52
  • 2
    Please provide a reproducible example of input and don't use image for code/data, use **text** – mozway Jun 07 '23 at 11:56
  • 1
    Refrain from showing your dataframe as an image. Your question needs a minimal reproducible example consisting of sample input, expected output, actual output, and only the relevant code necessary to reproduce the problem. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Jun 07 '23 at 13:58

1 Answers1

0

This is easily done using conditionals in pandas. For example for open_zones_from_stories:

open_zones = df["open_zones_from_stories"] > 0 # returns an array of True/False
open_zones_count = len(df[open_zones]) # returns number of occurences > 0

You can use any conditionals and any aggregate functions like .count(), .mean() or .std(). This is arguably easier than SQL, it's just a matter of knowing the right approach. I suggest going through the basics in the pandas docs.

Quantum
  • 510
  • 1
  • 2
  • 19