Python Forum
Read exel with merged cells and write to another excel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read exel with merged cells and write to another excel
#1
Hi,
I read the excel sheet which has "merged cells", and I want to write to another file retaining original merged cells.

My input excel is below:

Group	Name	Date	    Item	  Value
Group1	VGT	   2016-06-06	Power	  0
	    BHA	   2016-06-07	Voltage	  1
Group2	BNA	   2016-06-08	Volume	  1
	    KAL	   2016-06-09	AAA	      0
	    PAR	   2016-06-10	ANM	      0
Group3	VGT	2016-06-11	    Power	  1
I read and write another file, but can not retain merged cells.


row 2 is empty, row4~row5 again empty (but need to be merged with row3 ie, Group2)
Group	Name	Date	            Item	Value
Group1	VGT	   2016-06-06 00:00:00	Power	 0
empty	BHA	   2016-06-07 00:00:00	Voltage	 1
Group2	BNA	   2016-06-08 00:00:00	Volume	 1
empty	KAL	   2016-06-09 00:00:00	AAA	     0
empty	PAR	   2016-06-10 00:00:00	ANM	     0
Group3	VGT	   2016-06-11 00:00:00	Power	 1
How to retain the oroginal merged cells,

I sue below code:

#%%
import pandas as pd
infile='D:\\mergedinput.xlsx'
df=pd.read_excel(infile)
but the output is as below:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Write from dictionary to excel divon 3 3,470 Jun-11-2023, 10:37 AM
Last Post: Larz60+
Smile How to further boost the data read write speed using pandas tjk9501 1 1,228 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  Split excel file and write output at specific row and set sheet position DSCA 0 1,958 May-12-2022, 07:29 PM
Last Post: DSCA
  [Pandas] Write data to Excel with dot decimals manonB 1 5,774 May-05-2021, 05:28 PM
Last Post: ibreeden
  Python - Merge existing cells of Excel file created with xlsxwriter manonB 0 3,686 Mar-10-2021, 02:17 PM
Last Post: manonB
  Python read Excel cell data validation anantpatil 0 4,105 Jan-31-2020, 04:57 PM
Last Post: anantpatil
  how read and write merged cells in excel SriMekala 1 15,060 Aug-07-2019, 11:27 PM
Last Post: scidam
  Python write result of VAR to excel file wissam1974 8 8,521 Jul-13-2019, 01:09 PM
Last Post: wissam1974
  Two dataframes merged Ecniv 10 5,135 Jun-16-2019, 09:10 PM
Last Post: Ecniv
  Python read Password protected excel and convert to Pandas DataFrame FORTITUDE 2 17,022 Aug-30-2018, 01:08 PM
Last Post: FORTITUDE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020