0

I want to create a column that answers if string values from column 'A' are in either column 'B' or 'C'. These can be converted to float or int if that makes it easier.

Data:
 A    B    C       OUTPUT
 A    B    C     No/False
 B    B    B     Yes/True
 A    A    C     Yes/True
 A    C    A     Yes/True
It_is_Chris
  • 13,504
  • 2
  • 23
  • 41

2 Answers2

0

You can do

df["output"] = df.apply(lambda x: True if x["a"] in (x["b"], x["c"]) else False)
Sociopath
  • 13,068
  • 19
  • 47
  • 75
0

Let us try sin

df[['B','C']].isin(df.A).any(1)

0    False
1     True
2     True
3     True
dtype: bool
BENY
  • 317,841
  • 20
  • 164
  • 234