I'm trying to output a Pandas dataframe into an excel file using pandas dataframe need to merge rows with same value in column pandas.
eg :
pd.DataFrame({' Name': ['ravi', 'ravi', 'manu'],
'Bag': ['123', '123', '129'],
'Serial Number': ['336', '337','335']})
Need to merge both the rows (Name and Bag) as they are having same values
I was not able to merge those rows using pandas
If need merge same values in Excel convert first columns to MultiIndex
:
df = pd.DataFrame({' Name': ['ravi', 'ravi', 'manu'],
'Bag': ['123', '123', '129'],
'Serial Number': ['336', '337','335']})
df = df.set_index([' Name', 'Bag'])
df.to_excel('file.xlsx', merge_cells=True)
精彩评论