开发者

Merge rows based on value without using xlswriter but by using pandas dataframe [duplicate]

This question already has answers here: Concatenate 开发者_如何学编程strings from several rows using Pandas groupby (8 answers) Closed 3 hours ago.

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜