Skip to content
Advertisement

How to search a dataframe value based on another dataframe value?

I have two DFs:

JavaScript

Now I would like to compare the two dfs and put a column ‘True’ in df2 when the color column of df2 is residing in df1.

desired output:

JavaScript

I came up with the following:

JavaScript

However got the following error:

JavaScript

And tried the following

JavaScript

ValueError: Length of values (5) does not match length of index (10798)

Advertisement

Answer

IIUC, Series.isin:

JavaScript

Or np.isin:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement