Reputation: 63
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
i want out put as
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
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
Upvotes: 1
Views: 2335
Reputation: 702
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()
Upvotes: 3