Fluxy
Fluxy

Reputation: 2978

eval throws "TypeError: unhashable type: 'numpy.ndarray'"

I have the following pandas DataFrame df:

   Col1    Col2
0  NaN     Type1
1  NaN     Type2
2  NaN     Type1
3  A       Type1
4  NaN     Type1

I need to get indices of rows that have Col1 equal to NaN and Col2 equal to Type1. This is what I tried:

ix = df.eval("Col1.isna() and Col2== 'Type1'")

But it gives me the following error:

TypeError: unhashable type: 'numpy.ndarray'

Upvotes: 1

Views: 364

Answers (2)

Ekaba Bisong
Ekaba Bisong

Reputation: 2982

Do something like this:

df.index[df['Col1'].isna() & df['Col2'].eq('Type1')].tolist()

This should work, was just able to run it.

Upvotes: 1

zipa
zipa

Reputation: 27879

Try this:

df.loc[(df['Col1'].isna())&(df['Col2'].eq('Type1'))]

Upvotes: 0

Related Questions