-1

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?

beridzeg45
  • 246
  • 2
  • 11
  • This is probably not a full solution, but you are using back ticks: ` rather than single quotes: ' – henning Apr 17 '23 at 10:45
  • I am using backticks, because it is required in Pandas query function when the column name contains space. There was no issue, when I ran the same code in Jupyter Notebook – beridzeg45 Apr 17 '23 at 10:48
  • Please, provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). If your question include a pandas dataframe, please provide a [reproducible pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – alec_djinn Apr 17 '23 at 11:08
  • 1
    kaggle notebook can be found on this link: https://www.kaggle.com/code/beridzeg45/notebook3a64db585b/edit – beridzeg45 Apr 17 '23 at 11:22

1 Answers1

0

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"])]