# Comparing the values column by column

I'm currently stuck with this problem where I need to compere the value of each row and its next value column-wise with some strict rules to follow:

1. The value that should be compared should be > 0 else it should be False
2. It will only be True if the value being compared is less than the next value
• 1 to 2 = True
• 1 to 3 = True
• 2 to 3 = True

Dateset:

``````data = [[1,2,3,3,None,None],
[3,2,3,1,3,None],
[3,3,-1,3,2,1],
[2,3,1,2,3,None],
[-1,0,1,2,3,None]
]

data = pd.DataFrame(data)
data.columns = [f"Col{v + 1}"  for v in range(len(data.columns))]
data
``````

Expected Result:

``````result = [[True,True,False,False,False,False],
[False,False,True,False,True,False],
[False,False,False,False,False,False],
[True,False,True,True,False,False],
[False,False,True,True,False,False]
]

result = pd.DataFrame(result)
result.columns = [f"Col{v + 1}"  for v in range(len(result.columns))]
result
``````

My solution here is to create a nested loop but I don't think it is the optimal solution:

``````consolidated_list = []

for x in range(df.shape[1]):
row_val = []
for y in range(df.shape[0]):

if df.loc[y, df.columns[x]] < df.loc[y, df.columns[x + 1]]:
row_val.append(True)

#and so on...
``````