Source Code:
(back to article)
# create a sample DataFrame df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]}) # 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)) & (df['C']>8)] print(filtered_df)
Result:
Report an issue