import pandas as pd df = pd.DataFrame({'A': [1, 2, 3, 4, 5], 'B': [1, 4, 2, 6, 5]}) # get the positions where values of columns A and B match matches = df.query('A == B').index print(matches)