I managed with great help from here to export to xlsx appending on rows on a different sheet if needed. The issue I keep having is that when saving, it goes like this
example:
| a1 | b2 | c3 | d4 | e5 |
a1| 0 | 1 | 2 | 3 | 4 |
b2| sth | prc | some|else |here |
c3| 0 | 1 | 2 | 3 | 4 |
d3| sth1|prc2 |some1|esle2|here3|
The writer/reader code is the following, I have tried the.style, I have tried to set the index to None, I have tried to.reset_index(drop=True) but nothing did the trick.
data = pd.DataFrame(data =all_together)
data=data.transpose()
writer= pd.ExcelWriter('FromPython.xlsx',engine='openpyxl')
writer.book = load_workbook('FromPython.xlsx')
writer.sheets=dict((ws.title,ws) for ws in writer.book.worksheets)
reader = pd.read_excel(r'FromPython.xlsx',sheet_name=month)
data.to_excel(writer,sheet_name=month,header=month, index = False,startrow=len(reader)+1)
writer.save()
* Edit result that I need *
all_together[input1,input2,input3,input4,input5]
| a1 | b2 | c3 | d4 | e5 |
a1| sth |prc | some|else |here |
b2| sth1|prc2 |some1|else2|here3|
c3| sth2|prc3 |some2|else3|here4|
d3| sth3|prc4 |some3|esle4|here5|
I do not want the index on columns to be shown. I just want the results added as it does, without the index row.
Ok that I didn't check, the issue was the header and not the index. So I set header=False in the data.to_excel() and prints out as it should. Sorry for that everyone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.