How to filter a Pandas DataFrame with a list by in or not in in Python

Filtering a Pandas DataFrame with a list by in results in a new DataFrame with only the rows which contain a value in the list. Filtering by not in results in a new DataFrame with only the rows which don’t contain a value in the list.

Solution for How to filter a Pandas DataFrame with a list by in or not in in Python : You can use pandas.DataFrame.isin() to filter a DataFrame using a list Use pandas.DataFrame.isin(values) with pandas.DataFrame as a column in a DataFrame to get a boolean series indicating whether each element in pd.DataFrame is in the list values. Subset a DataFrame using this series to get a new DataFrame with only rows which contain a value in values. To get rows which don’t contain a value in values, insert ~ before the boolean series.


how-to-filter-a-pandas-dataframe-with-a-list-by-in-or-not-in-in-python