3

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?

2 Answers 2

12

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)

Sign up to request clarification or add additional context in comments.

1 Comment

On why pd.Series might not be able to be handled by insert wherever it used to work, some recent-ish changes that make pandas structs less like numpy dataframes is probably the culprit. Numpy just probably handled it gracefully in the conversion. I've gotten the error before "Error: Object of type <Pandas.Dataframe> is not a Pandas.Dataframe" in the midst of that happening.
2

You can using !=

df_data.query('a!=a')
Out[10]: 
    a
2 NaN

Since np.NaN not equal to np.NaN

1 Comment

I get ValueError: unknown type object when trying this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.