Kben59
Kben59

Reputation: 388

Check if values are > 0 in a DataFrame

I have this dataframe :

d =pd.DataFrame({'Values': [4, 5, 56, 5, 6, 35]})

And I want to print True if the last 3 values are >0

This is what I've done

d[-3:]>0

And I got

   Values
3   True
4   True
5   True

But this is not exactly what I want. I want to check the last 3 value and if they are all >0 then print True otherwise print False.

Thank you for the help

Upvotes: 0

Views: 31

Answers (1)

Ando
Ando

Reputation: 375

you can use all()

(d[-3:]>0).all()

Upvotes: 1

Related Questions