Trying to teach myself coding to automate some tedious tasks at work. I apologize for any unintentional ignorance.
I have created Data Frames in pandas (python 3.x). I want to print each data frame to a different excel sheet. Here is what I have for 2 Data Frames, it works perfect but I want to scale it to loop through a list of data frames so that I can make it a bit more dynamic.
writer = pandas.ExcelWriter("MyData.xlsx", engine='xlsxwriter')
Data.to_excel(writer, sheet_name="Data")
ByBrand.to_excel(writer, sheet_name="ByBrand")
writer.save()
Easy enough, but when there are 50+ sheets that need to be created it will get tedious.
Here is what I tried, it did not work:
writer = pandas.ExcelWriter("MyData.xlsx", engine='xlsxwriter')
List = [Data , ByBrand]
for i in List:
i.to_excel(writer, sheet_name= i)
writer.save()
I think the issue is that the sheet_name field must be a string because as-is it creates an error. But if I put sheet_name= "i", it only creates one sheet called "i" with the data from Data, but doesn't iterate to ByBrand. Also, the excel file would be a nightmare if the sheets weren't named to their corresponding data frame, so please no suggestions for things like numbered sheets.
Thank you so much in advance, this website has been invaluable for my journey into coding.
-Stephen