flying_fluid_four
flying_fluid_four

Reputation: 764

Unalignable boolean Series provided as indexer

I am trying to filter a dataframe as:

a= a[~(b['var1'].isin(c['var2']))]

but get the following error:

"Unalignable boolean Series provided as "
pandas.core.indexing.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).

I understand that the statement:

print(~(b['var1'].isin(c['var2'])) [:10])

is returning a series that is boolean masked which may not be acceptable. So, I tried to use loc as:

a= a.loc[:, ~(b['var1'].isin(c['var2']))]

but I am getting the same error. What am I missing here? Any input would be appreciated.

Thanks

Upvotes: 4

Views: 14468

Answers (1)

jezrael
jezrael

Reputation: 862671

Error means there are different index of a and of mask created with isin, it means different index of b.

mask = ~(b['var1'].isin(c['var2']))

So possible solution is change index by a.index and for not matched values add Falses:

a[mask.reindex(a.index, fill_value=False)]

Or:

a[~(b['var1'].reindex(a.index, fill_value=False).isin(c['var2']))]

Upvotes: 5

Related Questions