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, 2022 in Others by Kithuzzz
• 38,000 points
503 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, 2022 by narikkadan
• 63,600 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, 2022 in Others by narikkadan
• 63,600 points
848 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, 2022 in Others by narikkadan
• 63,600 points
710 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, 2022 in Others by narikkadan
• 63,600 points
612 views
0 votes
1 answer
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 4,434 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, 2022 in Others by narikkadan
• 63,600 points
348 views
0 votes
1 answer

Is there any way in python to auto-correct spelling mistake in multiple rows of an excel files of a single column?

Use Spellchecker for doing your stuff: import pandas ...READ MORE

answered Oct 14, 2022 in Others by narikkadan
• 63,600 points
2,054 views
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