1

I have imported an excel file, changed B1 and exported it, but I don't want to have a row (the first row) as a Header. I would like to write my data in the first row of my DataFrame exactly in the row number 1 of my excel sheet. here is what I wrote:

# import
df = pd.read_excel("DataName.xlsx", sheetname=0, header=None)

# setting the field B1 to a string
df.iloc[0,1] = "my text"

# Export
writer = pd.ExcelWriter(mypath, engine='xlsxwriter')
df.to_excel(writer, sheet_name= new_sheet, index=False)
writer.save()

but the exported Excel fale doesn't contain "my text" in B1. instead contains "1" and has a Header in row one like [0, 1, 2, ...]

"my text" is written to B2.

`

Mohsen
  • 25
  • 4

1 Answers1

1

Pandas has a header attribute you can set to false, and you can slice off the indexes if index=False is not working, so it would look like:

df.to_excel(writer, sheet_name= new_sheet, index=False,header=False).drop(['unnamed 0'],axis=1)

See this answer for more details https://stackoverflow.com/a/42978156/2779192

bruckerrlb
  • 185
  • 2
  • 7