Skip to content
Advertisement

How can we create separate excel sheets using python pandas?

For ex: I have one excel file as my input, consisting of 50K records of employees. Employees are working in different companies A,B, and C.

How can we filter this input excel file on the basis of companies and create new output Excel file. Which consist of separate sheets For Companies A,B, and C.

In output excel file Sheet A should have only employees working in A company. Sheet B should have only employees working in B company. Sheet C should have only employees working in C company.

Advertisement

Answer

You can try the following:

df=pd.read_excel('your_main_file.xlsx')

writer = pd.ExcelWriter('output.xlsx', engine = 'xlsxwriter')
for i in set(df['Company']):
    temp = df[df.Company == i]
    temp.to_excel(writer, sheet_name='Company_'+str(i))

writer.save()
writer.close()  
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement