比较Excel文件中的列

时间:2018-11-28 09:08:58

标签: excel python-3.x list

我的Excel文件包含4列: file1.xls:

ID  Name   Sal  City
1   Mark  1500   A
2   Nancy 2500   B
3   John  2700   B
4   Tom   2000   A
5   Lena  2200   A

在基于相同(城市)值的列之间进行比较时, (Sal)值大于1000可获得匹配。

这是我的尝试:

from xlrd import open_workbook

Id_list = []
book = open_workbook("d:/file1.xlsx")
for sheet in book.sheets():
    for rowidx in range(1,sheet.nrows):
        row = sheet.row(rowidx)
        for colidx, cell in enumerate(row):
                if cell.value == "A":
                   Id_list.append(sheet.cell_value(rowidx, 0))

我仅基于(城市)获得比赛ID,但是如何显示这样的比赛ID。 应该是这样的:

id    match_id     City
1     4,5           A
2     3             B
3     2             B
4     1,5           A
5     1,4           A

有帮助吗?...

0 个答案:

没有答案