Check if the pandas series has at least one item greater than

The following code will print True because the Series contains at least one element that is greater than 1. However, it seems a little non-neat. Is there a more Pythonic way to return True if the series contains a number that is a value>

import pandas as pd s = pd.Series([0.5, 2]) print True in (s > 1) 

True

EDIT: Not only is the above non-Pythonic answer, it sometimes returns an incorrect result for some reason. For instance:

 s = pd.Series([0.5]) print True in (s < 1) 

False

+5
source share
1 answer

You can use any method to check if this condition is True for at least one value:

 In [36]: (s > 1).any() Out[36]: True 
+7
source

Source: https://habr.com/ru/post/1237629/


All Articles