python - 如何将dataframe导入到excel且不覆盖原有内容
PHP中文网
PHP中文网 2017-04-18 10:31:21
0
2
2495

使用了pandas的to_excel方法,但每次都会覆盖原来的内容。
请问还有什么方法可以将dataframe格式的数据导入到excel呢?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
刘奇

Choose one of two methods:

  1. df.to_csv, parameter mode='a' means append

  2. df.to_excel, put the df values ​​together before writing. For example, the original data is df1, and the data to be written is df2
    then pandas.concat([df1, df2]).to_excel()

阿神

to_excel supports many parameters, among which:

startrow:
upper left cell row to dump data frame
startcol:
upper left cell column to dump data frame

Before writing the excel file, first get the number of rows used in excel, and write the number of rows to start in to_excel

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template