How to get separate excel file of the data frame from a list?
I don't want to make 4 separate functions for each costcenter
.
import pandas as pd
df = pd.read_excel(r'c:\temp\code.xlsx')
costcenter = ['1130', '1236', '3427', '3148' ]
for each_costcenter in costcenter:
y = df[df['COST CENTER']== each_costcenter]
y.to_excel(r'c:\temp\code\finalput.xlsx', sheet_name=each_costcenter)
I thought I can get finalput
with 4 sheets of the data but I end up with one sheet with the last from the list.
I wouldn't mind getting 4 separate files with cost center names.