I want to write a data frame to excel. I have done it using pandas pivot table. I have passed the column names as indexes. I am getting the excel, but it's in bold letters, I only need the column names as bold the values need to be in normal font.
import pandas as pd
# Create a test df
df = pd.DataFrame(
{'Name': ['ravi', 'Deepthy','ravi'],
'Ship': ['mount everes', 'mount everes', 'Oasis of the Seas'],
'Tracking': ['TESTTRACK003', 'TESTTRACK008', 'TESTTRACK009'],
'Bag': ['123', '129', '129'],
})
df=pd.pivot_table(df,values=["Name","Ship","Tracking","Bag"],
index=["Name","Ship","Tracking","Bag"])
def normal_font(_):
return "font-weight: normal"
df.style.applymap_index(normal_font).to_excel("abcde.xlsx", engine="openpyxl",startrow=-1)
CodePudding user response: