Reputation: 85
I have dictionary containing dataframes. I have to export them to excel to one file with sheets having one dataframe in each sheet with its name. How can I do this? Manually would be like this:
dict_of_regions = dict(iter(data.groupby('blok')))
marketing = dict_of_regions['marketing']
hr = dict_of_regions['hr ']
with pd.ExcelWriter('C:\\Users\\Desktop\\to_excel.xlsx') as writer:
marketing.to_excel(writer, sheet_name='marketing')
hr.to_excel(writer, sheet_name='hr')
Upvotes: 0
Views: 127
Reputation: 120391
Loop over your dict_of_regions
:
with pd.ExcelWriter('C:\\Users\\Desktop\\to_excel.xlsx') as writer:
for sheet_name, df in dict_of_regions.items():
df.to_excel(writer, sheet_name)
Upvotes: 2