I have a df such that
c_name f_name
0 abc abc12
1 xyz abc1
2 mnq mnq2
The goal is to find a substring across the two columns an know which column it belongs to. Preference should be to c_name
, as in if the substring is in both the columns then c_name
gets precedence For eg: if I search for abc
in the above dataframe I should somehow get row 0 abc
for c_name
and row 1 abc1
for f_name
.
To solve this I started with
df[df['c_name'].str.contains('abc', case=False)]
which will give me the results for c_name
. The question now is to how to exclude the rows where I already have the results from performing the same operation on f_name
. Any help is greatly appreciated!