I have been trying to test if any value in a series appears in a column in a dataframe, however it appears that the way I have been doing it returns True regardless of whether the values appear or not.
For example, using the below dataframe and series:
df = pd.DataFrame({'Col1' : [1, 2, 2, 6, 4, 8],
'Col2' : [11, 11, 11, 11, 11, 11]})
Col1 Col2
0 1 3
1 2 3
2 2 3
3 6 3
4 4 3
5 8 3
series = pd.Series([3, 5, 9])
0 3
1 5
2 9
dtype: int64
I want to check if any value in series appears in Col1 (which it doesn't in this example, so should evaluate to False). The method I've been using to check this is:
if True in series.isin(df['Col1']):
Which evaluates to True despite the fact that the output of series.isin(df['Col1']) is a series of only False. I was wondering why this is the case and is there a better way to check if a value in a series is in a dataframe? I know I can use if any(series.isin(df['Col1'])), is this the best way?
(Pandas version: 1.1.3)