Skip to content

Instantly share code, notes, and snippets.

@OlegKorn
Last active January 27, 2024 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OlegKorn/1cf8befa67ea44cdb1f5471ca5fade28 to your computer and use it in GitHub Desktop.
Save OlegKorn/1cf8befa67ea44cdb1f5471ca5fade28 to your computer and use it in GitHub Desktop.
import pandas as pd
import openpyxl
# maybe in loop
for i in data: # let i == [a, b]
df = pd.DataFrame(
[[a, b]],
columns=['Title1', 'Title2']
)
with pd.ExcelWriter(
"title.xlsx",
mode="a", # append instead of making new each time
engine="openpyxl",
if_sheet_exists="overlay" # idk
) as writer:
df.to_excel(
writer,
sheet_name="new_sheet_name",
header=None,
startrow=writer.sheets["new_sheet_name"].max_row,
index=False
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment