I am working on writing multiple dataframes in excel spreadsheets within an excel file. The dataframes generates using for loop , so in every iteration I get next available dataframe but I can not able to write every dataframe in spreadsheets. I could only write the first dataframe in first spreadsheet. Below is the code snippet:
writer = pd.ExcelWriter('output.xlsx', engine='xlsxwriter')
workbook = writer.book
web_ClassID=df_stag["Web-Class ID"].unique()
for data_id, df in df_stag.groupby('Web-Class ID'):
for workbook_Id in web_ClassID:
if workbook_Id == data_id:
for index, col in enumerate(df):
df.to_excel(writer,sheet_name=workbook_Id,index=False )
writer.save()
workbook.close()
Note: The webclass_id here is type of object Df_stag: is a dataframe which is grouped by Webclass_id df is the dataframe which I want to write into excel spreadsheets Also, I am creating spreadsheets whenever a new Webclass_id is found , so the tab gets created with corresponding Webclass_id when found.One file having few tabsanother file having few tabs
Output: I want a single excel file having all the tabs from all the files and appended data from those file which have same tab in both the files. ie. 11111,22222,33333 and data from 11111 should be from both the files.
for
loop? And why increment loop iterators? Plus you have indentation issues and finally, your post seems cut off. Please edit so we can help. – Parfait