for loop questions python matching excel
<p>I am trying to go through an entire row of cells and compare it to the row of cells on another excel sheet. i have figured it out so that it reads from the sheet, but there must be something wrong with my for loops and if statements. what i am doing is assigning the first cell and then comparing it to the first cell in the other sheet. if they are equal i want it to write a ' ' in a different sheet, at the point of that row in the first sheet. if they aren't the same, i want to see if the first 6 digits are the same, and if they are... i want to write "CHECK" on that cell on the first sheet. i want to keep going down the cells in the second sheet, and until that is all checked, move on to the next cell in the first sheet and start over. </p>

<p>what is wrong with my code here? it is outputting the wrong outputs into the excel sheet.</p>

<p>thank you.</p>

<pre><code>for row in range(sheet.nrows):
     cell = str(sheet.cell_value(row, 0))

         for row in range(windc_sheet.nrows):

             windcell = str(windc_sheet.cell_value(row, 0));

             if cell == windcell:
                outputsheet.write(row, 1, ' ')
             else:
                sixdig = cell[0:6]
                sixdigwind = windcell[0:6]
                if sixdig == sixdigwind:
                    outputsheet.write(row, 1, 'Check')
         else:
             continue;


 else:
     continue


error output onto excel:        wanted output:

check                            check
check              
check 
check                            check 
check
</code></pre>

<p>two sheets being compared:</p>

<pre><code> 123456-01            123455-01
 124445               123336-55
 123454-99            123456-02
 123455-03            133377-66
 1277                 199227-22
</code></pre>

<p>Second iteration is the one that is making the error. Just try this:</p>

<pre><code>for row in range(sheet.nrows):
    cell = str(sheet.cell_value(row, 0))
    windcell = str(windc_sheet.cell_value(row, 0))
    if cell == windcell:
       outputsheet.write(row, 1, ' ')
    else:
       sixdig = cell[0:6]
       sixdigwind = windcell[0:6]
       if sixdig == sixdigwind:
           outputsheet.write(row, 1, 'Check')
</code></pre>

python excel for-loop