File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,30 @@ which is almost always what you want anyways.
8888
8989 See :ref: `boolean comparisons<basics.compare> ` for more examples.
9090
91+ Using the ``in `` operator
92+ ~~~~~~~~~~~~~~~~~~~~~~~~~
93+
94+ Using the Python ``in `` operator on a Series tests for membership in the
95+ index, not membership among the values.
96+
97+ .. ipython ::
98+
99+ s = pd.Series(range(5), index=list('abcde'))
100+ 2 in s
101+ 'b' in s
102+
103+ If this behavior is surprising, keep in mind that using ``in `` on a Python
104+ dictionary tests keys, not values, and Series are dict-like.
105+ To test for membership in the values, use the method :func: `~pandas.Series.isin `:
106+
107+ .. ipython ::
108+
109+ s.isin([2])
110+ s.isin([2]).any()
111+
112+ For DataFrames, likewise, ``in `` applies to the column axis,
113+ testing for membership in the list of column names.
114+
91115``NaN ``, Integer ``NA `` values and ``NA `` type promotions
92116---------------------------------------------------------
93117
You can’t perform that action at this time.
0 commit comments