I am very beginner in python. I was trying to find out if any value matches with any row from the data and another given value matches with the next row of it, then print the first row and continue until the last row
import pandas as pd
df= pd.read_csv ("prac.csv")
n = 0
a = input ("write the 1st number: ")
b = input ("write the 2nd number: ")
while n < 5 :
if df.loc[n:n] == a:
if df.loc[n+1:n+1] == b:
print (df.loc[n:n])
else: print ("No match")
n+=1
Column 1 | Column 2 | Column 3 | Column 4 |
---|---|---|---|
4 | 35 | 3 | 66 |
10 | 22 | 12 | 23 |
5 | 3 | 21 | 21 |
88 | 29 | 2 | 7 |
37 | 39 | 33 | 1 |
For example if 1st value (4) matches with any row (row 1) any 2nd value (22) with the next row (row 2) of it then it should print the row it matched first and continue. I am trying to run the code but its not working.
Column 1 | Column 2 | Column 3 | Column 4 |
---|---|---|---|
4 | 35 | 3 | 66 |