写一个python代码,在不修改原工作表第1,第2行内容的条件下,将dateframe从excel表格第3行开始覆盖到excel工作表之中,
时间: 2023-03-10 19:16:51 浏览: 97
Python3读取和写入excel表格数据的示例代码
答案:
```
import pandas as pdexcel_file = 'filename.xlsx'
df = pd.read_excel(excel_file, header=2)with pd.ExcelWriter(excel_file, engine='openpyxl', mode='w') as writer:
writer.book = openpyxl.load_workbook(excel_file)
writer.sheets = dict((ws.title, ws) for ws in writer.book.worksheets)
df.to_excel(writer, sheet_name='Sheet1', index=False, header=False, startrow=2)
writer.save()
```
阅读全文