What is the quickest way to check if the given pandas series contains a negative value.
For example, for the series s
below the answer is True
.
s = pd.Series([1,5,3,-1,7])
0 1
1 5
2 3
3 -1
4 7
dtype: int64
isin() function check whether values are contained in Series. It returns a boolean Series showing whether each element in the Series matches an element in the passed sequence of values exactly.
Use any
>>> s = pd.Series([1,5,3,-1,7])
>>> any(s<0)
True
You can use Series.lt
:
s = pd.Series([1,5,3,-1,7])
s.lt(0).any()
Output:
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With