循环使用Excel电子表格(使用openpyxl) [英] Looping through an Excel spreadsheet (using openpyxl)
问题描述
import openpyxl
wb = openpyxl.load_workbook('Book_1.xlsx')
ws = wb ['Sheet_1']
我正在尝试使用openpyxl分析一个excel电子表格。我的目标是从列A中的每组数字中获取D列的最大数量。我希望帮助获取代码循环用于分析。这是我试图分析的电子表格的一个例子。文件名为Book 1,表格名称为Sheet 1.我正在运行Python 3.6.1,pandas 0.20.1和openpyxl 2.4.7。我提供了迄今为止的代码。
I am trying to analyze an excel spreadsheet using openpyxl. My goal is to get the max number from column D for each group of numbers in column A. I would like help in getting a code to loop for the analysis. Here is an example of the spreadsheet that I am trying to analyze. The file name is Book 1 and the sheet name is Sheet 1. I am running Python 3.6.1, pandas 0.20.1, and openpyxl 2.4.7. I am providing the code I have so far.
推荐答案
IIUC,使用 pandas
模块来实现:
IIUC, use pandas
module to achieve this:
import pandas as pd
df = pd.read_excel('yourfile.xlsx')
maxdf = df.groupby('ID').max()
maxdf将具有您要查找的结果。
maxdf will have the result you are looking for.
这篇关于循环使用Excel电子表格(使用openpyxl)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!