KOTA ITO

Generation

generate functionThu, 15 Dec 2022

openpyxlを使って、Excelファイルの一列目に'Japan'が含まれる行を全て抜き出す。次にそれらの行を新しいExcelファイルに格納する。 その後、3列目に含まれる日付で行をグルーピングして、日付ごとに新しいシートに格納する。

import openpyxl # open the input file in_file = openpyxl.load_workbook('test.xlsx') in_sheet = in_file.active # create a new file out_file = openpyxl.Workbook() out_sheet = out_file.active out_sheet.title = 'Japan' # copy data for row in in_sheet.rows: if row[0].value == 'Japan': out_sheet.append(row) # write the output file out_file.save('out.xlsx')

Questions about programming?Chat with your personal AI assistant