query() and isin() combination is not working in Kaggle notebook

40 Views Asked by At

I want to filter dataframe using .query() and .isin() functions in Kaggle notebook.

standard_stats=standard_stats.query('`Unnamed: 0_level_0_Player`.isin(["Squad Total","Opponent Total"])==False')

Unnamed: 0_level_0_Player is the name of the column and ["Squad Total","Opponent Total"] is the list of values, that should not be in the filtered dataframe.

After running this code, I get the following error: TypeError: unhashable type: 'numpy.ndarray'.

I did not get the error, when I ran the code in Jupyter Notebook. How can I resolve the problem?

1

There are 1 best solutions below

2
achrafhamid On

The .isin() func does not accept the np array you passed, because an np array is a non hashable object. try using the .loc()

standard_stats = standard_stats.loc[~standard_stats['Unnamed: 0_level_0_Player'].isin(["Squad Total", "Opponent Total"])]