Python Forum
Split excel file and write output at specific row and set sheet position
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split excel file and write output at specific row and set sheet position
#1
Hi All,

I have a Masterfile which I split with the help of codes. Below is the code I use for splitting the excel file based on a column.

import pandas as pd #pip install pandas
import os

df = pd.read_excel('CE Version - Drewry December Masterfile - v5.xlsx')
column_name = 'Member Name'
unique_values = df[column_name].unique()

for unique_value in unique_values:
    df_output = df[df[column_name].str.contains(unique_value)]
    output_path = os.path.join('output',unique_value + '.xlsx')
    df_output.to_excel(output_path, sheet_name=unique_value, index=False) 
Question:- I want the data in splited files from row 17. Means top 16 rows should be empty in each splited files. And, I want to add one empty sheet as well in each splited files. How is it possible ?
Larz60+ write May-13-2022, 09:03 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I fixed your indentation as well, please check that it's in proper place. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Write from dictionary to excel divon 3 3,712 Jun-11-2023, 10:37 AM
Last Post: Larz60+
  Data Sorting and filtering(From an Excel File) PY_ALM 0 1,045 Jan-09-2023, 08:14 PM
Last Post: PY_ALM
  How to write table to different sheet in openpyxl rsearing 2 2,082 Aug-22-2022, 11:59 PM
Last Post: Pedroski55
  [Pandas] Write data to Excel with dot decimals manonB 1 5,872 May-05-2021, 05:28 PM
Last Post: ibreeden
  Creating more than one excel File at once malvarez1976 0 1,813 Dec-15-2020, 02:04 AM
Last Post: malvarez1976
  Convert Excel to .txt - Need each excel row to be separate .txt file cowboykevin05 2 4,787 Jan-03-2020, 06:29 PM
Last Post: Larz60+
  [split] Converting excel file to txt file unexceptionalhobby 2 4,350 Oct-16-2019, 06:34 PM
Last Post: unexceptionalhobby
  Read exel with merged cells and write to another excel SriMekala 0 2,976 Aug-10-2019, 07:14 AM
Last Post: SriMekala
  how read and write merged cells in excel SriMekala 1 15,122 Aug-07-2019, 11:27 PM
Last Post: scidam
  Python write result of VAR to excel file wissam1974 8 8,600 Jul-13-2019, 01:09 PM
Last Post: wissam1974

Forum Jump:

User Panel Messages

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