Q:

How to loop through comparing one column with its corresponding column in Python

I have an excel file which I imported as a dataframe. I want to loop through the columns of the dataframe. For eg, I want to compare 2nd column with first , then 3rd column with second.I have converted rule_id column into index. This is the data:
rule_id reqid1  reqid2  reqid3
53139   0         0      1
51181   1         1      0
50412   0         1      1
50356   0         0      1
50239   0         1      0
50238   1         1      0
50014   1         0      1      

And this is the code I am using.
for n in fin2.columns[0:]:
    n = 0
    n_int = int(n)
    if ([fin2.iloc[: , n_int+1] != fin2.iloc[: , n_int]]):
        print dframe2

    if ([fin2.iloc[: , n_int+1] == fin2.iloc[: , n_int]]):
        print dframe3
    n = n+1

With this code , I am only able to compare second column with first , I have set the value of n to 0 and also applied the logic , n=n+1 which increments the value of n every time the conditions fulfills. Your help would be much appreciated.
I have created these two functions:
def solved_prior(df):
    n = 0
    n_int = int(n)
    df['solved_prior'] = np.where(df.iloc[: , n_int+1] < df.iloc[: , n_int] , 100 , np.nan)
    return df

and 
def repeated_prior(df):
    n = 0
    n_int = int(n)
    df['repeated_prior'] = np.where((df.iloc[: , n_int+1] == df.iloc[: , n_int]) & (df.iloc[: , n_int] == 1) , 1 , np.nan)
    return df

I have stored these functions in daframe2 and dataframe3 respectively. I want the result for first comparison between 2nd and 1st column as:
rule_id reqid1  reqid2  reqid3 solved prior repeated prior
    53139   0         0      1    NaN          NaN
    51181   1         1      0    NaN           1
    50412   0         1      1    NaN          NaN
    50356   0         0      1    NaN          NaN
    50239   0         1      0    NaN          NaN
    50238   1         1      0    NaN           1
    50014   1         0      1    100          NaN 

And the result for the comparison between column 3rd and 2nd should look like this:
  rule_id reqid1     reqid2 reqid3 solved prior repeated prior
    53139   0         0      1       NaN          NaN
    51181   1         1      0       100          NaN
    50412   0         1      1       NaN           1
    50356   0         0      1       NaN          NaN
    50239   0         1      0       100          NaN
    50238   1         1      0       NaN          NaN
    50014   1         0      1       NaN          NaN 

A:

Like one of the comments state, your expected output could influence what the best solution is. Keeping that in mind, looping over columns is rarely the best solution. I suggest simply adding new columns that indicate whether the columns being compared are equal or not. For instance:
In [1]: import pandas as pd

In [2]: df = pd.DataFrame({'rule_id': [53139,51181,50412,50356,50239,50238,50014], 'reqid1':[0,1,0,0,0,1,1],'reqid2':[0,1,1,0,1,1,0],'reqid3':[1,0,1,1,0,0,1]})

In [3]: df
Out[3]: 
   rule_id  reqid1  reqid2  reqid3
0    53139       0       0       1
1    51181       1       1       0
2    50412       0       1       1
3    50356       0       0       1
4    50239       0       1       0
5    50238       1       1       0
6    50014       1       0       1

In [4]: df['compare_1_and_2'] = df.reqid1 == df.reqid2

In [5]: df
Out[5]: 
   rule_id  reqid1  reqid2  reqid3  compare_1_and_2
0    53139       0       0       1             True
1    51181       1       1       0             True
2    50412       0       1       1            False
3    50356       0       0       1             True
4    50239       0       1       0            False
5    50238       1       1       0             True
6    50014       1       0       1            False

In [6]: df['compare_2_and_3'] = df.reqid2 == df.reqid3

In [7]: df
Out[7]: 
   rule_id  reqid1  reqid2  reqid3  compare_1_and_2  compare_2_and_3
0    53139       0       0       1             True            False
1    51181       1       1       0             True            False
2    50412       0       1       1            False             True
3    50356       0       0       1             True            False
4    50239       0       1       0            False            False
5    50238       1       1       0             True            False
6    50014       1       0       1            False            False

Now if the columns are very long, you might find any() and all() useful. To see if any of the values are true (There is at least one value that is identical):
In [8]: df.compare_1_and_2.any()
Out[8]: True

And to see if all values are true (The columns are identical):
In [9]: df.compare_1_and_2.all()
Out[9]: False

Edit: (to match expected output)
Now it is a simple matter of using the boolean columns to match what you require
df['solved_prior_1_vs_2'] = np.NaN
df['repeated_prior_1_vs_2'] = np.NaN
df.loc[(df.compare_1_and_2 == False) & (df.reqid1 == 1),'solved_prior_1_vs_2'] = 100
df.loc[(df.compare_1_and_2 == True) & (df.reqid1 == 1),'repeated_prior_1_vs_2'] = 1

And the results look like this:
In [27]: df[['rule_id','reqid1','reqid2','solved_prior_1_vs_2','repeated_prior_1_vs_2']]
Out[27]: 
   rule_id  reqid1  reqid2  solved_prior_1_vs_2  repeated_prior_1_vs_2
0    53139       0       0                  NaN                    NaN
1    51181       1       1                  NaN                    1.0
2    50412       0       1                  NaN                    NaN
3    50356       0       0                  NaN                    NaN
4    50239       0       1                  NaN                    NaN
5    50238       1       1                  NaN                    1.0
6    50014       1       0                100.0                    NaN

You can now remove the columns you don't need, and do the same for comparing 2 to 3. Also may convert new columns to ints.
Final edit(Hopefully):
A simpler solution is to just define a function such as:
def compare_columns(df, col1, col2):
    repeated_name = "{}_{}_repeated".format(col1, col2)
    solved_name = "{}_{}_solved".format(col1, col2)
    diff = df[col1] == df[col2]
    col1_is_1 = df[col1] == 1
    df[repeated_name] = 100
    df[solved_name] = 1
    df[repeated_name] = df[repeated_name].astype(int)
    df[solved_name] = df[sovled_name].astype(int)
    df.loc[~(diff & col1_is_1), solved_name] = np.NaN
    df.loc[~(~diff & col1_is_1), repeated_name] = np.NaN
    return df

And now you can just do:
In [42]: df1 = compare_columns(df, 'reqid1', 'reqid2')
In [43]: df1
Out[43]: 
   rule_id  reqid1  reqid2  reqid3  reqid1_reqid2_repeated  reqid1_reqid2_solved
0    53139       0       0       1                     NaN                   NaN
1    51181       1       1       0                     NaN                   1
2    50412       0       1       1                     NaN                   NaN
3    50356       0       0       1                     NaN                   NaN
4    50239       0       1       0                     NaN                   NaN
5    50238       1       1       0                     NaN                   1
6    50014       1       0       1                     100                   NaN

