I have df with two columns A and B both of them are columns with string values.
Example:
df_1 = pd.DataFrame(data={
"A":['a','b','c'],
"B":['a x d','z y w','q m c'] #string values not a list
})
print(df_1)
#output
A B
0 a a x d
1 b z y w
2 c q m c
now what I'm trying to do is to preform loc in the df_1 to get all the row that col B cointain the string value in col A.
In this example the output i want is the first and the third rows:
A B
0 a a x d # 'a x d' contain value 'a'
2 c q m c # 'q m c' contain value 'c'
I have tried different loc condition but got unhashable type: 'Series' error:
df_1.loc[df_1["B"].str.contains(df_1["A"])] #TypeError: unhashable type: 'Series'
df_1.loc[df_1["A"] in df_1["B"]] #TypeError: unhashable type: 'Series'
I really don't want to use a for/while loop because of the size of the df.
Any idea how can I preform this?