I'm trying to export multiple dataframes from python to excel, I wrote a for loop to do so. Following an answer from another thread https://stackoverflow.com/a/54237619/12350323 . I think the structure of my code is the same as the one from that thread.
The problem is that I don't get the expected result when I run the code . What I should be getting (the way I intended the code to work) is 8 sheets, every loop generating two different dataframes, one with my function applied and another one with dropped values, "redummy" and "deldummy" and this done four times.
What I get instead is two exact copies of the dataframe with my function applied in every loop. That is, I get two "redummy"s, but they have a different sheet name, so I end up with 8 sheets, with only four that are different, so I think my code is going through the loop, but deldummy doesn't show up for some reason. I don't really understand why this is happening. I hope you can help me, thanks in advance.
import pandas as pd
from pandas import ExcelWriter
w = ExcelWriter(r'C:\Users\DATA\Downloads\data int.xlsx')
for i in range(4):
dummy = pd.read_excel(r'C:\Users\UNI\Downloads\DATA.xlsx', sheet_name = "M" + i)
redummy = poly_fill(dummy, 4) #a function of my own, it shouldn't change "dummy"
deldummy = dummy.dropna()
redummy.to_excel(w, sheet_name = "L4 " + i + "%", index = False)
deldummy.to_excel(w, sheet_name = "del " + i + "%", index = False)
w.save()