Lisa
Lisa

Reputation: 271

Merge rows based on value (pandas to excel - xlsxwriter) - addition

Following up this question

I would like to ask if we could merge rows from multiple columns, i.e.

enter image description here

Following answers from @Dimitris Thomas, I would be able to obtain the following

enter image description here

And wondering how the code could be updated to get:

enter image description here

Thanks

Upvotes: 5

Views: 1795

Answers (1)

Anurag Dabas
Anurag Dabas

Reputation: 24314

IIUC:

Firstly:

df=pd.read_excel('filename.xlsx')
#read excel file in pandas

try via set_index() and to_excel()

df.set_index(df.columns[:-1].tolist()).to_excel('filename.xlsx',header=None)
#OR(Since you don't provide data as text so not sure which one should work)
df.set_index(df.columns.tolist()).to_excel('filename.xlsx',header=None)

Upvotes: 6

Related Questions