I am trying to find a combination where it will go through the data to find matched variables for any value from the list First_row is found, any value from the list Second_row and any value from the list Third_row is found. import pandas as pd import numpy as np import csv df= pd.read_csv ("data.csv") b2=1 #assigning variables c2=2 d2=3 b3=4 c3=5 d3=6 b4=7 c4=8 d4=9 First_row = [b2, c2, d2] #list for first row Second_row = [b3, c3, d3] #list for second row Third_row = [b4, c4, d4] #list for third row for n in range(len(df)): # data for i in range(len(First_row)): if df.loc[n].isin(First_row).any(): # Found a value from First_row for i in range(len(Second_row)): if df.loc[n+1].isin(Second_row).any(): ## Found a value from Second_row for i in range(len(Third_row)): if df.loc[n+2].isin(Third_row).any(): # Found a value from Third_row print(First_row,Second_row,Third_row) # print the variables If the first row has any one of [b2, c2, d2], second row has any one of [b3, c3, d3] and third row has any one of [b4, c4, d4] then it will print the variables, not the assigned value. It will search as b2,b3,b4, -> b2,b3,c4, -> b2,b3,d4, -> b2,c3,b4, etc. and print the variables (not the assigned value) when found and continue. I am trying to run it but it's showing "only list-like objects are allowed to be passed to isin()" Continue reading...