I have a pandas dataFrame
in which I would like to check if one column is contained
in another.
Suppose:
df = DataFrame({'A': ['some text here', 'another text', 'and this'],
'B': ['some', 'somethin', 'this']})
I would like to check if df.B[0]
is in df.A[0]
, df.B[1]
is in df.A[1]
etc.
Current approach
I have the following apply
function implementation
df.apply(lambda x: x[1] in x[0], axis=1)
result is a Series
of [True, False, True]
which is fine, but for my dataFrame shape
(it is in the millions) it takes quite long.
Is there a better (i.e. faster) implamentation?
Unsuccesfull approach
I tried the pandas.Series.str.contains
approach, but it can only take a string for the pattern.
df['A'].str.contains(df['B'], regex=False)