Check if a pandas Series has at least one item greater than a value
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Jungle Looping
--
Chapters
00:00 Check If A Pandas Series Has At Least One Item Greater Than A Value
00:38 Accepted Answer Score 52
00:50 Answer 2 Score 1
01:41 Thank you
--
Full question
https://stackoverflow.com/questions/3414...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas
#avk47
    Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Jungle Looping
--
Chapters
00:00 Check If A Pandas Series Has At Least One Item Greater Than A Value
00:38 Accepted Answer Score 52
00:50 Answer 2 Score 1
01:41 Thank you
--
Full question
https://stackoverflow.com/questions/3414...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas
#avk47
ACCEPTED ANSWER
Score 52
You could use any method to check if that condition is True at least for the one value:
In [36]: (s > 1).any()
Out[36]: True
ANSWER 2
Score 1
in operator a.k.a __contains__() method checks if a specific value exists as an index in a Series.
s = pd.Series([0.5], index=['a'])
'a' in (s > 1)          # True
'b' in s                # False
As a side note, in operator used on dataframes checks if a value exists as a column label.
df = pd.DataFrame([[1]], columns=['a'])
'a' in df               # True
'b' in df               # False
In other words, the fact that the in operator returns True or False has nothing to do with whether (s > 1) has any True values in it or not. In order to make the membership test work, the values must be accessed.
True in (s < 1).values  # True
Reducing the values into a single boolean value (as suggested by @Anton Protopopov) is the canonical way to this task. Python's built-in any() function may be called as well.
any(s > 1)              # False
s.gt(1).any()           # False
(s < 1).any()           # True
s.lt(1).any()           # True