I have a pandas Dataframe and a pandas Series that looks like below.
df0 = pd.DataFrame({'col1':['a','b','c','d'],'col2':['b','c','e','f'],'col3':['d','f','g','a']})
col1 col2 col3
0 a b d
1 b c f
2 c e g
3 d f a
df1 = pd.Series(['b','g','g'], index=['col1','col2','col3'])
col1 b
col2 g
col3 g
dtype: object
As you can see, the columns of df0
and the indices of df1
are the same. For each index of df1
, I want to know if the value at that index exists in the corresponding column of df0
. So, df1.col1
is b
and we need to look for b
only in df0.col1
and check if it exists.
Desired output:
array([True, False, True])
Is there a way to do this without using a loop? Maybe a method native to numpy or pandas?