how to check whether ALL elements in a Pandas series are equal to a specific value

Viewed 2771

For a given series, e.g.

s = pd.Series([0,0,0])

I would like to check whether ALL elements in this series are equal to a specific value (we can use 0 in this example) and return TRUE if that is the case, and FALSE otherwise.

is there a handy way to do those in Pandas/numpy?

2 Answers

You should use the following syntax:

s = pd.Series([0,0,0])

print(s.eq(0).all())
True

Another way to do the same would be:

print((s==0).all())
Related