Looping through an Excel spreadsheet (using openpyxl)

空扰寡人 提交于 2019-12-02 13:35:55

IIUC, use pandas module to achieve this:

import pandas as pd
df = pd.read_excel('yourfile.xlsx')
maxdf = df.groupby('ID').max()

maxdf will have the result you are looking for.

Let's say you have file test.xlsx with worksheet ws1. Try:

from openpyxl import load_workbook
wb = load_workbook(filename='test.xlsx')
ws = wb['ws1']

for col in ws.columns:
    col_max = 0
    for cell in col:
        if cell.value > col_max:
            col_max = cell.value
    print('next max:', col_max)

I'm looping over all the rows because I'm not sure what you've expected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!