I need to read an Excel sheet named 'Input' make some operations and write the result into an new sheet 'Output'. I am creating a new Pandas dataframe that I need to write into my 'Output' Sheet. I need to concatenate all the results on this Sheet
Here is the structure of my code :
import pandas as pd
import math
import numpy
from openpyxl import load_workbook
df = pd.read_excel('Test.xlsx', sheet_name="Input")
for i in range(len(df)):
if A:
data = (...)
# Create the pandas DataFrame
new_df = pd.DataFrame(data, columns = ['X','Y'])
print("New DF")
print(new_df)
elif B:
data = (...)
# Create the pandas DataFrame
new_df = pd.DataFrame(data, columns = ['X','Y'])
print("New DF")
print(new_df)
elif C:
data = (...)
# Create the pandas DataFrame
new_df = pd.DataFrame(data, columns = ['X','Y'])
print("New DF")
print(new_df)
else:
print("WARNING")
with pd.ExcelWriter("Test.xlsx", engine="openpyxl", mode="a") as writer:
new_df.to_excel(writer, sheet_name="Output", index=False)
My code is working but it creates several Sheets Output1,Output2,Output3,...
How can I fix this to have only one Output Sheet that contains all my results ?
Thank you