Basically the following code returns the position of a character in column ‘a’ in another string (in this case ‘}JKLMNOPQR’). In this example, column ‘b’ has the same value in all rows, but it could have different values.
Is there a vectorized way to do this?
frame = pd.DataFrame({'a' : ['L', '}', 'P']})
frame['b']='}JKLMNOPQR'
frame['c'] = frame.apply(lambda row: row.b.find(row.a), axis=1)
frame
a b c
0 L }JKLMNOPQR 3
1 } }JKLMNOPQR 0
2 P }JKLMNOPQR 7
Vectorized way of finding position of one column value in another in Pandas