Skip to content

ENH: Dataframe should have a .isin() method #4211

Closed
@TomAugspurger

Description

@TomAugspurger

Any reason not to give DataFrame a .isin() method like Series?

The new wrinkle is that the user needs to specify if they want a logical OR or AND.

e.g.

In [26]: df = pd.DataFrame({'vals': [1, 2, 3, 4], 'ids': ['a', 'b', 'f', 'f'], 
'ids2': ['e', 'f', 'c', 'f']})

In [27]: df
Out[27]: 
  ids ids2  vals
0   a    e     1
1   b    f     2
2   f    c     3
3   f    f     4

In [1]: other_ids = pd.Series(['a', 'b', 'c', 'c'])

df.isin(other_ids, how='or')

  ids ids2  vals
0   a    e     1
1   b    f     2
2   f    c     3

df.isin(other_ids, how='and')

See this SO post maybe.

If someone else wants to take this, feel free. Can't promise a PR any time soon, but maybe in the fall :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions