search

Home  >  Q&A  >  body text

python - 如何将dataframe导入到excel且不覆盖原有内容

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

PHP中文网PHP中文网2876 days ago2529

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-04-18 10:33:21

    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()

    reply
    0
  • 阿神

    阿神2017-04-18 10:33:21

    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

    reply
    0
  • Cancelreply