Dataframe 在比较前两列时,无法将正确的状态放入另一列

Dataframe 在比较前两列时,无法将正确的状态放入另一列,dataframe,python-3.7,openpyxl,data-analysis,xlrd,Dataframe,Python 3.7,Openpyxl,Data Analysis,Xlrd,我正在尝试运行以下代码段,但没有得到所需的输出。实际上,我正在尝试比较excel文件中的两个单元格,并将True/False打印到“Status”列中。请参考下面的代码片段和输出。另请参阅excel输出。需要帮助 for i in range(sheet.max_row + 1): for j in range(1, sheet.max_column): print(i) print(j) if i == j: if

我正在尝试运行以下代码段,但没有得到所需的输出。实际上,我正在尝试比较excel文件中的两个单元格,并将True/False打印到“Status”列中。请参考下面的代码片段和输出。另请参阅excel输出。需要帮助

for i in range(sheet.max_row + 1):
    for j in range(1, sheet.max_column):
        print(i)
        print(j)
        if i == j:
            if sheet.cell(row=i, column=j).value == sheet.cell(row=i, column=j + 1).value:
                print('inside true case')
                sheet.cell(row=i, column= sheet.max_column).value = 'True'
            else:
                print('inside false case')
                sheet.cell(row=i, column=sheet.max_column).value = 'False'
        print('----')


    C:\Users\Sambhav\PycharmProjects\ParallelRunUtility\venv\Scripts\python.exe C:/Users/Sambhav/PycharmProjects/ParallelRunUtility/main.py
(10, 1)
(17, 1)
              Unit_Price_x  Unit_Price_y Status
PolicyNumber                                   
12345               231.49        569.72       
45678               208.93        208.93       
0
1
----
0
2
----
0
3
----
1
1
inside false case
----
1
2
----
1
3
----
2
1
----
2
2
inside false case
----
2
3
----
3
1
----
3
2
----
3
3
inside false case
----

Process finished with exit code 0