I have a total of 4 (df1, df2, df3, df4) pandas data frames. I would like to create a single excel sheet with 4 worksheets named 'Sheet1', 'Sheet2', 'Sheet3', 'Sheet4' and would like to see each worksheet tab with different colors.
I have been trying with pandas but I cannot able to set the color. Please advise.
import padas as pd
writer = pd.ExcelWriter('example.xlsx',
engine='xlsxwriter')
df1.to_excel(writer, sheet_name='Sheet1')
df2.to_excel(writer, sheet_name='Sheet2')
df3.to_excel(writer, sheet_name='Sheet3')
df4.to_excel(writer, sheet_name='Sheet4')
writer.save()
I guess you might be looking for this ...if you add worksheet then it will conflict with already in use error. First add your df and do other stuff with writer and xlsxwriter engine.
import pandas as pd
import xlsxwriter
df1 = pd.DataFrame([1,2,3,4,5,6])
writer = pd.ExcelWriter('example.xlsx', engine='xlsxwriter')
df1.to_excel(writer, sheet_name= 'Sheet1')
worksheet1 = writer.sheets['Sheet1']
worksheet1.set_tab_color('green')
writer.save()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With