These methods enable the user to achieve more with Boolean indexing than the standard operators used in the preceding sections. The isin method takes a list of values and returns a Boolean array with True at the positions within the Series or DataFrame that match the values in the list. This enables the user to check for the presence of one or more elements within a Series. Here is an illustration using Series:
In[317]:stockSeries=pd.Series(['NFLX','AMZN','GOOG','FB','TWTR']) stockSeries.isin(['AMZN','FB']) Out[317]:0 False 1 True 2 False 3 True 4 False dtype: bool
Here, we use the Boolean array to select a sub-series containing the values that we're interested in:
In [318]: stockSeries[stockSeries.isin(['AMZN','FB'])] ...