Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas Python Series objects are mutable, thus they cannot be hashed in query method

Tags:

python

pandas

I'm tring to run:

import pandas as pd
df_data = pd.DataFrame({'a':[1,20,None,40,50]})
df_data.query('a.isnull()')

and an error happens :

TypeError: 'Series' objects are mutable, thus they cannot be hashed

but:

df_data.a.isnull()

has no error at all, why is this happening? can you help me to figure out why?

like image 978
Jordi Puigdellivol Avatar asked Mar 17 '26 07:03

Jordi Puigdellivol


1 Answers

Use python engine, or use a np.array with the default npexpr engine.

df_data.query('a.isnull()', engine='python')

or

df_data.query('a.isnull().values')

(Not quite sure why numexpr can't handle a pd.Series though)

like image 82
rafaelc Avatar answered Mar 18 '26 19:03

rafaelc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!