I am trying to export a dataframe that I create in python to excel by group. I would like to create a new separate excel file for each group, not sheets within he same excel file.
This is the code I have right now and it creates sheets within the same excel file for each group. How can I alter this to create separate excel files. Do I need to write a for loop? Many of the solutions I am finding on Stack Overflow seem to be pointing in that direction.
data = df.groupby('ID')
writer = pd.ExcelWriter('Data_New.xlsx', engine='xlsxwriter')
for row,group in data:
group.to_excel(writer, index = None, sheet_name=row)
writer.save()
Data_New.xlsx. You need multiple filenames if you want multiple files.