The following code will print True because the Series contains at least one element that is greater than 1. However, it seems a bit un-Pythonic. Is there a more Pythonic way to return True if a Series contains a number that is > a particular value?
import pandas as pd s = pd.Series([0.5, 2]) print True in (s > 1)
True
EDIT: Not only is the above answer un-Pythonic, it will sometimes return an incorrect result for some reason. For example:
s = pd.Series([0.5]) print True in (s < 1)
False
Compare two Series objects of the same length and return a Series where each element is True if the element in each Series is equal, False otherwise. Compare two DataFrame objects of the same shape and return a DataFrame where each element is True if the respective element in each DataFrame is equal, False otherwise.
You can check if a column contains/exists a particular value (string/int), list of multiple values in pandas DataFrame by using pd. series() , in operator, pandas. series. isin() , str.
Pandas DataFrame: ge() function The ge() function returns greater than or equal to of dataframe and other, element-wise. Equivalent to ==, =!, <=, <, >=, > with support to choose axis (rows or columns) and level for comparison.
iloc attribute enables purely integer-location based indexing for selection by position over the given Series object. Example #1: Use Series. iloc attribute to perform indexing over the given Series object.
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
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