Source Code:
(back to article)
import pandas as pd # create a sample DataFrame df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) # create a list of values to filter for values_to_filter = [2, 3] # use the ~ (not in) operator along with the isin() method to filter the DataFrame filtered_df = df[~df['A'].isin(values_to_filter)] print(filtered_df)
Result:
Report an issue