Last active
July 14, 2021 17:00
-
-
Save StefanoGITA/858ead92186d438f7fa03c5a8329a2a3 to your computer and use it in GitHub Desktop.
python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openpyxl import load_workbook | |
from openpyxl.utils.dataframe import dataframe_to_rows | |
template_fout = "<the name of empty excel file to use as template>" | |
fout_name = "<the name of excel file where save the data>" | |
... | |
... | |
... | |
# df_values is the DataFrame with the data to save | |
wb = load_workbook(fout_name) | |
sheet = wb.active | |
df_columns = df_values.shape[1] | |
# I use 2 with enumerate to save the header column of the excel sheet | |
for r, row in enumerate(dataframe_to_rows(df_values, index=False, header=False), 2): | |
for c in range(0, df_columns): | |
sheet.cell(row=r, column=c + 1).value = row[c] | |
wb.save(fout_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment