@@ -7451,52 +7451,66 @@ def to_period(self, freq=None, axis=0, copy=True):
7451
7451
7452
7452
def isin (self , values ):
7453
7453
"""
7454
- Return boolean DataFrame showing whether each element in the
7455
- DataFrame is contained in values.
7454
+ Whether each element in the DataFrame is contained in values.
7456
7455
7457
7456
Parameters
7458
7457
----------
7459
- values : iterable, Series, DataFrame or dictionary
7458
+ values : iterable, Series, DataFrame or dict
7460
7459
The result will only be true at a location if all the
7461
7460
labels match. If `values` is a Series, that's the index. If
7462
- `values` is a dictionary , the keys must be the column names,
7461
+ `values` is a dict , the keys must be the column names,
7463
7462
which must match. If `values` is a DataFrame,
7464
7463
then both the index and column labels must match.
7465
7464
7466
7465
Returns
7467
7466
-------
7467
+ DataFrame
7468
+ DataFrame of booleans showing whether each element in the DataFrame
7469
+ is contained in values.
7468
7470
7469
- DataFrame of booleans
7471
+ See Also
7472
+ --------
7473
+ DataFrame.eq: Equality test for DataFrame.
7474
+ Series.isin: Equivalent method on Series.
7475
+ Series.str.contains: Test if pattern or regex is contained within a
7476
+ string of a Series or Index.
7470
7477
7471
7478
Examples
7472
7479
--------
7473
- When ``values`` is a list:
7474
-
7475
- >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'f']})
7476
- >>> df.isin([1, 3, 12, 'a'])
7477
- A B
7478
- 0 True True
7479
- 1 False False
7480
- 2 True False
7481
-
7482
- When ``values`` is a dict:
7483
-
7484
- >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [1, 4, 7]})
7485
- >>> df.isin({'A': [1, 3], 'B': [4, 7, 12]})
7486
- A B
7487
- 0 True False # Note that B didn't match the 1 here.
7488
- 1 False True
7489
- 2 True True
7490
-
7491
- When ``values`` is a Series or DataFrame:
7492
-
7493
- >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'f']})
7494
- >>> df2 = pd.DataFrame({'A': [1, 3, 3, 2], 'B': ['e', 'f', 'f', 'e']})
7495
- >>> df.isin(df2)
7496
- A B
7497
- 0 True False
7498
- 1 False False # Column A in `df2` has a 3, but not at index 1.
7499
- 2 True True
7480
+
7481
+ >>> df = pd.DataFrame({'num_legs': [2, 4], 'num_wings': [2, 0]},
7482
+ ... index=['falcon', 'dog'])
7483
+ >>> df
7484
+ num_legs num_wings
7485
+ falcon 2 2
7486
+ dog 4 0
7487
+
7488
+ When ``values`` is a list check whether every value in the DataFrame
7489
+ is present in the list (which animals have 0 or 2 legs or wings)
7490
+
7491
+ >>> df.isin([0, 2])
7492
+ num_legs num_wings
7493
+ falcon True True
7494
+ dog False True
7495
+
7496
+ When ``values`` is a dict, we can pass values to check for each
7497
+ column separately:
7498
+
7499
+ >>> df.isin({'num_wings': [0, 3]})
7500
+ num_legs num_wings
7501
+ falcon False False
7502
+ dog False True
7503
+
7504
+ When ``values`` is a Series or DataFrame the index and column must
7505
+ match. Note that 'falcon' does not match based on the number of legs
7506
+ in df2.
7507
+
7508
+ >>> other = pd.DataFrame({'num_legs': [8, 2],'num_wings': [0, 2]},
7509
+ ... index=['spider', 'falcon'])
7510
+ >>> df.isin(other)
7511
+ num_legs num_wings
7512
+ falcon True True
7513
+ dog False False
7500
7514
"""
7501
7515
if isinstance (values , dict ):
7502
7516
from pandas .core .reshape .concat import concat
0 commit comments