You can do this effectively with numpy.argwhere:
import pandas as pd, numpy as np
df = pd.DataFrame([[947.2, 1.25, 'BAM 1.25'],
[129.3, 2.1, 'NAD 1.25'],
[161.69, 0.8, 'CAD 2.00']],
columns=['Price', 'Rate p/lot', 'Total Comm'])
res = np.argwhere(df.values.astype('<U3') == 'NAD')
This gives you an array of coordinates where your match will match.
To get one tuple:
res = next(map(tuple, np.argwhere(df.values.astype('<U3') == 'NAD')))
List of lines:
res = list(map(tuple, np.argwhere(np.logical_or.reduce(\
[df.values.astype('<U3') == i for i in np.array(['BAM', 'NAD'])]))))
source
share