[Python] Pandas를 활용하여 엑셀 시트별로 만들기

2020. 10. 20. 22:29분석 Python/Pandas Tip

728x90

한 엑셀 파일에 여러 데이터를 담아두고 싶을 때 사용할 수 있다.

 

우리가 엑셀을 사용할 때 여러 엑셀 시트를 만드는 것과 동일하게 생각하면 됨.

 

어려운 것은 아니지만, 까먹을 수 있으므로 남겨둔다.

with pd.ExcelWriter(f"./../../data/processed/hw/info.xlsx") as writer:  
    dataset = [###]
        for idx , data in enumderate(datasets) :
			####
        	data.to_excel(writer, sheet_name=str(idx), index=False)

 

추가적으로 이미지 넣기

import xlsxwriter


# Create an new Excel file and add a worksheet.
workbook = xlsxwriter.Workbook('images.xlsx')
worksheet = workbook.add_worksheet()

# Widen the first column to make the text clearer.
worksheet.set_column('A:A', 30)

# Insert an image.
worksheet.write('A2', 'Insert an image in a cell:')
worksheet.insert_image('B2', 'python.png')

# Insert an image offset in the cell.
worksheet.write('A12', 'Insert an image with an offset:')
worksheet.insert_image('B12', 'python.png', {'x_offset': 15, 'y_offset': 10})

# Insert an image with scaling.
worksheet.write('A23', 'Insert a scaled image:')
worksheet.insert_image('B23', 'python.png', {'x_scale': 0.5, 'y_scale': 0.5})

workbook.close()
728x90