title: Write the output from "for" loop to excel in PYTHON
body: <p>I have the following piece of code:</p>
  
  <pre><code>my_list = ["US", "IT", "ES", "NL"]
  for i in my_list:
      A = sum_products_by_country(world_level,i)
      df = pd.DataFrame({'value':A})
      Descending = df.sort_values( by='value', ascending = 0 )
      Top_5 = Descending[0:5]
      print(Top_5)
  </code></pre>
  
  <p>The "sum_products_by_country" is a created function which takes as arguments a data frame ( in my case is named "world_level") and a country name and returns  the sum by product for this country. Using this loop I find the top5 products and the sums for each country of my_list. Here is the output of this loop:</p>
  
  <pre><code>US          value
  Product  
  
  
  B          1492
  
  H          455
  
  BB         351
  
  C          119
  
  F          117
  
  IT          value
  Product
  
  
  P           346
  U           331
  
  A           379
  
  Q           190
  
  D          1389
  
  ES         value
  Product 
  
  
  P          3046
  
  U3         331
  
  A          379
  
  Q          1390
  
  DD         10389
  
  NL         value
  Product 
  
  
  P          3465
  
  U          3313
  
  AA         379
  
  2Q         190
  
  D          189
  </code></pre>
  
  <p>I want to write this output in a excel sheet using :</p>
  
  <pre><code>writer = pd.ExcelWriter('top products.xlsx', engine='xlsxwriter')
  Top_5.to_excel(writer, sheet_name='Sheet1')
  writer.save()
  </code></pre>
  
  <p>Could you tell me where should I put the code above in order to get the required excel document?
  Is there also a way to get the column names(country,product,value) only once on the top in my excel document and not for each country separately? So I want something like this:</p>
  
  <pre><code> Country   Product   value
  
    US        
             B          1492
             H          455
             BB         351
             C          119
             F          117
  
    IT          
  
             P           346
             U           331
             A           379
             Q           190
             D          1389
  
    ES         
  
            P          3046
            U3         331
            A          379
            Q          1390
            DD         10389
  
    NL         
  
            P          3465
            U          3313
            AA         379
            2Q         190
            D          189
  </code></pre>
  
  <p>Thank you</p>