'Pandas remove certain headers from the dataframe while exporting
I have a table which is similar as shown below :
| OpenTable | ||
|---|---|---|
| One | Two | Three |
| A | B | C |
| Four | Five | Six |
| D | E | F |
When I read it in pandas with df = pd.read_excel('myfilename.xlsx') function. I used pandas to remove the Nan values from a particular column.
It adds headers names to the empty headers like below:
| OpenTable | Unnamed: 1 | Unnamed: 2 |
|---|---|---|
| One | Two | Three |
| A | B | C |
| Four | Five | Six |
| D | E | F |
When I export this file using df.to_excel('my filename.xlsx')
It still retains the headers as below, Is there any way to ignore those and write to excel?
Solution 1:[1]
df.to_excel('my fillename.xlsx', header=['OpenTable', '', ''])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
