1

experts, i want to remove a very first row from excel file using python. I am sharing a a screen print of my source excel file enter image description here

i want out put as

enter image description here

I am using below python code to remove first row from excel but when i am reading it as data frame and printing that i am observing that data in data frame is being read as shown in below screen print

enter image description here

and the code which i am using is

import pandas as pd
import os
def remove_header():
 file_name = "AV Clients.xlsx"
 os.chmod(file_name, 0o777)
 df = pd.read_excel(file_name) #Read Excel file as a DataFrame
 #df = df.drop([0])
 print(df)
 #df.to_excel("AV_Clients1.xlsx", index=False)

remove_header()

Please suggest how i can remove a very first row from excel file whose screen print i have shared at top. Thanks in advance Kawaljeet

3

1 Answer 1

3

Just add skiprows argument while reading excel.

import pandas as pd
import os
def remove_header():
    file_name = "AV Clients.xlsx"
    os.chmod(file_name, 0o777)
    df = pd.read_excel(file_name, skiprows = 1) #Read Excel file as a DataFrame
    print(df)
    df.to_excel("AV_Clients1.xlsx", index=False)

remove_header()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.