pandas column is in another column code example

pandas column is in another column

1

1 Example

0
#if necessary strip ' in all values
df = df.apply(lambda x: x.str.strip("'"))
#df = df.applymap(lambda x: x.strip("'"))

print (df.apply(lambda x: x.A in x.B, axis=1))
0     True
1     True
2    False
dtype: bool

df = df[df.apply(lambda x: x.A in x.B, axis=1)]
print (df)
     A      B
0  lol  lolec
1  ram  rambo

Other Code Examples