With this code, it is possible to export every data frame in a new worksheet iterating 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?
Something like 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 ))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With