SammySharken
SammySharken

Reputation: 11

sheeting excel sheet after user id using a for loop

Data

Given the data above, I want to be able to name each excel sheet by the id. But the code only names sheet after last id.

Here is my code:

import pandas as pd
import xlsxwriter

df_dummy = pd.read_csv('dummy.csv') 

id_store = df_dummy['id'].unique()

for i in id_store:
    print (i)
    workbook_dummy = xlsxwriter.Workbook('store_dummy.xlsx')
    worksheet = workbook_dummy.add_worksheet('store {}'.format(i))
    workbook_dummy.close()

Upvotes: 1

Views: 40

Answers (1)

Jeanne
Jeanne

Reputation: 11

Try creating the XlsxWriter Workbook object before the for loop.

Upvotes: 1

Related Questions