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:

1
2
3
4
5
6
7
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)
1
2
3
4
5
6
7
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:

1
2
3
4
#%%
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 12,762 Jun-11-2023, 10:37 AM
Last Post: Larz60+
Smile How to further boost the data read write speed using pandas tjk9501 1 2,018 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  Split excel file and write output at specific row and set sheet position DSCA 0 2,741 May-12-2022, 07:29 PM
Last Post: DSCA
  [Pandas] Write data to Excel with dot decimals manonB 1 7,998 May-05-2021, 05:28 PM
Last Post: ibreeden
  Python - Merge existing cells of Excel file created with xlsxwriter manonB 0 4,813 Mar-10-2021, 02:17 PM
Last Post: manonB
  Python read Excel cell data validation anantpatil 0 4,956 Jan-31-2020, 04:57 PM
Last Post: anantpatil
  how read and write merged cells in excel SriMekala 1 16,838 Aug-07-2019, 11:27 PM
Last Post: scidam
  Python write result of VAR to excel file wissam1974 8 11,169 Jul-13-2019, 01:09 PM
Last Post: wissam1974
  Two dataframes merged Ecniv 10 6,922 Jun-16-2019, 09:10 PM
Last Post: Ecniv
  Python read Password protected excel and convert to Pandas DataFrame FORTITUDE 2 18,549 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