File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -997,6 +997,15 @@ a list of items you want to check for.
997
997
998
998
df.isin(values)
999
999
1000
+ To return the DataFrame of booleans where the values are *not * in the original DataFrame,
1001
+ use the ``~ `` operator:
1002
+
1003
+ .. ipython :: python
1004
+
1005
+ values = {' ids' : [' a' , ' b' ], ' vals' : [1 , 3 ]}
1006
+
1007
+ ~ df.isin(values)
1008
+
1000
1009
Combine DataFrame's ``isin `` with the ``any() `` and ``all() `` methods to
1001
1010
quickly select subsets of your data that meet a given criteria.
1002
1011
To select a row where each column meets its own criterion:
Original file line number Diff line number Diff line change @@ -10559,6 +10559,13 @@ def isin(self, values) -> DataFrame:
10559
10559
falcon True True
10560
10560
dog False True
10561
10561
10562
+ To check if ``values`` is *not* in the DataFrame, use the ``~`` operator:
10563
+
10564
+ >>> ~df.isin([0, 2])
10565
+ num_legs num_wings
10566
+ falcon False False
10567
+ dog True False
10568
+
10562
10569
When ``values`` is a dict, we can pass values to check for each
10563
10570
column separately:
10564
10571
Original file line number Diff line number Diff line change @@ -5012,6 +5012,17 @@ def isin(self, values) -> Series:
5012
5012
5 False
5013
5013
Name: animal, dtype: bool
5014
5014
5015
+ To invert the boolean values, use the ``~`` operator:
5016
+
5017
+ >>> ~s.isin(['cow', 'lama'])
5018
+ 0 False
5019
+ 1 False
5020
+ 2 False
5021
+ 3 True
5022
+ 4 False
5023
+ 5 True
5024
+ Name: animal, dtype: bool
5025
+
5015
5026
Passing a single string as ``s.isin('lama')`` will raise an error. Use
5016
5027
a list of one element instead:
5017
5028
You can’t perform that action at this time.
0 commit comments