Home 데이터프레임 엑셀 특정 시트로 변경(openpyxl)
Post
Cancel

데이터프레임 엑셀 특정 시트로 변경(openpyxl)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import openpyxl
import openpyxl.utils.dataframe import dataframe_to_rows

wb = openpyxl.Workbook()

# sheet 추가
wb.crate_sheet('sheet_name', 1) # sheet 순서

# 데이터프레임 준비
rows = dataframe_to_rows(df, index=False, header=True)

# 데이터프레임 -> excel sheet
for r_idx, row in enumerate(rows, 1):
	for c_idx, value in enumerate(row, 1):
		wb[sheet_name].cell(row=r_idx, column=c_idx, value=value)

wb.save('test.xlsx')
This post is licensed under CC BY 4.0 by the author.