<small id='Av2nU'></small><noframes id='Av2nU'>

    1. <legend id='Av2nU'><style id='Av2nU'><dir id='Av2nU'><q id='Av2nU'></q></dir></style></legend>
    2. <i id='Av2nU'><tr id='Av2nU'><dt id='Av2nU'><q id='Av2nU'><span id='Av2nU'><b id='Av2nU'><form id='Av2nU'><ins id='Av2nU'></ins><ul id='Av2nU'></ul><sub id='Av2nU'></sub></form><legend id='Av2nU'></legend><bdo id='Av2nU'><pre id='Av2nU'><center id='Av2nU'></center></pre></bdo></b><th id='Av2nU'></th></span></q></dt></tr></i><div id='Av2nU'><tfoot id='Av2nU'></tfoot><dl id='Av2nU'><fieldset id='Av2nU'></fieldset></dl></div>
        <bdo id='Av2nU'></bdo><ul id='Av2nU'></ul>

      1. <tfoot id='Av2nU'></tfoot>

        使用 Python 比较 2 个 excel 文件

        时间:2023-11-08
      2. <tfoot id='VKPI5'></tfoot>

        <i id='VKPI5'><tr id='VKPI5'><dt id='VKPI5'><q id='VKPI5'><span id='VKPI5'><b id='VKPI5'><form id='VKPI5'><ins id='VKPI5'></ins><ul id='VKPI5'></ul><sub id='VKPI5'></sub></form><legend id='VKPI5'></legend><bdo id='VKPI5'><pre id='VKPI5'><center id='VKPI5'></center></pre></bdo></b><th id='VKPI5'></th></span></q></dt></tr></i><div id='VKPI5'><tfoot id='VKPI5'></tfoot><dl id='VKPI5'><fieldset id='VKPI5'></fieldset></dl></div>

          <small id='VKPI5'></small><noframes id='VKPI5'>

        • <legend id='VKPI5'><style id='VKPI5'><dir id='VKPI5'><q id='VKPI5'></q></dir></style></legend>
              <tbody id='VKPI5'></tbody>
            • <bdo id='VKPI5'></bdo><ul id='VKPI5'></ul>

                1. 本文介绍了使用 Python 比较 2 个 excel 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个 xlsx 文件如下:

                  I have two xlsx files as follows:

                  value1   value2   value3
                  0.456   3.456    0.4325436
                  6.24654 0.235435 6.376546
                  4.26545 4.264543 7.2564523
                  

                  value1   value2  value3
                  0.456   3.456    0.4325436
                  6.24654 0.23546  6.376546
                  4.26545 4.264543 7.2564523
                  

                  我需要比较所有单元格,如果一个单元格来自 file1 != 一个单元格来自 file2 print 那.

                  I need to compare all cells, and if a cell from file1 != a cell from file2 print that.

                  import xlrd
                  rb = xlrd.open_workbook('file1.xlsx')
                  rb1 = xlrd.open_workbook('file2.xlsx')
                  sheet = rb.sheet_by_index(0)
                  for rownum in range(sheet.nrows):
                      row = sheet.row_values(rownum)
                      for c_el in row:
                          print c_el
                  

                  如何添加 file1file2 的比较单元格?

                  How can I add the comparison cell of file1 and file2 ?

                  推荐答案

                  以下方法应该可以帮助您入门:

                  The following approach should get you started:

                  from itertools import izip_longest
                  import xlrd
                  
                  rb1 = xlrd.open_workbook('file1.xlsx')
                  rb2 = xlrd.open_workbook('file2.xlsx')
                  
                  sheet1 = rb1.sheet_by_index(0)
                  sheet2 = rb2.sheet_by_index(0)
                  
                  for rownum in range(max(sheet1.nrows, sheet2.nrows)):
                      if rownum < sheet1.nrows:
                          row_rb1 = sheet1.row_values(rownum)
                          row_rb2 = sheet2.row_values(rownum)
                  
                          for colnum, (c1, c2) in enumerate(izip_longest(row_rb1, row_rb2)):
                              if c1 != c2:
                                  print "Row {} Col {} - {} != {}".format(rownum+1, colnum+1, c1, c2)
                      else:
                          print "Row {} missing".format(rownum+1)
                  

                  这将显示两个文件之间不同的任何单元格.对于您给定的两个文件,这将显示:

                  This will display any cells which are different between the two files. For your given two files, this will display:

                  Row 3 Col 2 - 0.235435 != 0.23546
                  

                  如果您更喜欢单元格名称,请使用 xlrd.formular.colname():

                  If you prefer cell names, then use xlrd.formular.colname():

                  print "Cell {}{}  {} != {}".format(rownum+1, xlrd.formula.colname(colnum), c1, c2)
                  

                  给你:

                  Cell 3B  0.235435 != 0.23546
                  

                  这篇关于使用 Python 比较 2 个 excel 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在列表中查找最旧/最年轻的日期时间对象 下一篇:删除python列表中的对象实例

                  相关文章

                  1. <legend id='VDurz'><style id='VDurz'><dir id='VDurz'><q id='VDurz'></q></dir></style></legend>

                    <i id='VDurz'><tr id='VDurz'><dt id='VDurz'><q id='VDurz'><span id='VDurz'><b id='VDurz'><form id='VDurz'><ins id='VDurz'></ins><ul id='VDurz'></ul><sub id='VDurz'></sub></form><legend id='VDurz'></legend><bdo id='VDurz'><pre id='VDurz'><center id='VDurz'></center></pre></bdo></b><th id='VDurz'></th></span></q></dt></tr></i><div id='VDurz'><tfoot id='VDurz'></tfoot><dl id='VDurz'><fieldset id='VDurz'></fieldset></dl></div>

                  2. <small id='VDurz'></small><noframes id='VDurz'>

                    <tfoot id='VDurz'></tfoot>

                      • <bdo id='VDurz'></bdo><ul id='VDurz'></ul>