title: Pandas: Iterate through a list of DataFrames and export each to excel sheets
body: <p>Trying to teach myself coding to automate some tedious tasks at work. I apologize for any unintentional ignorance. </p>
  
  <p>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.</p>
  
  <pre><code>writer = pandas.ExcelWriter("MyData.xlsx", engine='xlsxwriter')
  Data.to_excel(writer, sheet_name="Data")
  ByBrand.to_excel(writer, sheet_name="ByBrand")
  writer.save()
  </code></pre>
  
  <p>Easy enough, but when there are 50+ sheets that need to be created it will get tedious. </p>
  
  <p>Here is what I tried, it did not work:</p>
  
  <pre><code>writer = pandas.ExcelWriter("MyData.xlsx", engine='xlsxwriter')
  List = [Data , ByBrand]
  for i in List:
          i.to_excel(writer, sheet_name= i)
  writer.save()
  </code></pre>
  
  <p>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.</p>
  
  <p>Thank you so much in advance, this website has been invaluable for my journey into coding.</p>
  
  <p>-Stephen</p>