Looping Through An Excel Spreadsheet (using Openpyxl)
import openpyxl wb=openpyxl.load_workbook('Book_1.xlsx') ws=wb['Sheet_1'] I am trying to analyze an excel spreadsheet using openpyxl. My goal is to get the max number from column D
Solution 1:
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.
Solution 2:
Let's say you have file test.xlsx
with worksheet ws1
. Try:
from openpyxl importload_workbookwb= load_workbook(filename='test.xlsx')
ws = wb['ws1']
for col in ws.columns:
col_max = 0for 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.
Post a Comment for "Looping Through An Excel Spreadsheet (using Openpyxl)"