Export many small DataFrames to a single Excel worksheet

0 votes

With this code, it is possible to export every data frame in a new worksheet iterating the data frames list:

def save_xls(list_dfs, xls_path):
    writer = ExcelWriter(xls_path)
    for n, df in enumerate(list_dfs):
        df.to_excel(writer,'sheet_dati%s' % n)
    writer.save()
save_xls(list_dfs, xls_path)

But its possible to export two or more data frames in a single worksheet?

Nov 17 in Others by Kithuzzz
• 20,660 points
25 views

1 answer to this question.

0 votes

Try  this:

from pandas import ExcelWriter
def dfs2xlsx(list_dfs,xls_path = None):
    #save_xls([df1,df2],'output1.xlsx')
    if xls_path == None :
        xls_path = '~tmp.xlsx'
    writer = ExcelWriter(xls_path)
    i=0
    for n, df in enumerate(list_dfs):
        df.to_excel(writer,'Sheet1',startcol=i,startrow =2)
        i+= len(df.columns) + 2
    writer.save()
    os.system('start excel.exe %s' %(writer.path ))
answered Nov 17 by narikkadan
• 37,660 points

Related Questions In Others

0 votes
1 answer

How do I protect all worksheet in an Excel workbook with a single click?

VBA Code : Dim ws as Worksheet Dim pwd ...READ MORE

answered Oct 22 in Others by narikkadan
• 37,660 points
33 views
0 votes
1 answer

Using a UDF in Excel to update the worksheet

The MSDN KB is incorrect. It says A user-defined function called ...READ MORE

answered Nov 7 in Others by narikkadan
• 37,660 points
37 views
0 votes
1 answer

Using c# to select a worksheet in excel

Try this: Excel.Worksheet xlWorkSheetFocus = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2); xlWorkSheetFocus.Activate(); I hope this ...READ MORE

answered Nov 14 in Others by narikkadan
• 37,660 points
32 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 3,138 views
0 votes
1 answer
0 votes
1 answer

Many cells to a single reference in excel

Use conditional formatting to hide the A's ...READ MORE

answered Nov 5 in Others by narikkadan
• 37,660 points
21 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP