I would appreciate your help, I have the following code:
for embalse in ["PIL", "PUL", "VDV"]:
vo = pd.read_csv('...\Desktop\pucv.xlsx',encoding='utf-8')
vo=vo[vo["Embalse"]==embalse]
writer = ExcelWriter('...\Desktop\embalses.xlsx')
vo.to_excel(writer, embalse, index=False)
writer.save()
What I'm doing is rescuing data from a column whose name is variable and will depend on the path of for
, every time the loop ends, it is saved in an Excel and once again with the loop it will open the previously created file and just add the variable name "reservoir".
The problem is that it works but the file is overwritten, and finally an Excel file results with only one sheet whose name is the last one, "VDV".
How could I make sure that it is not overwritten and just add a new sheet, with the aim of ending with an Excel file with as many sheets as loops in for
made?