您的位置:首頁技術文章
文章詳情頁

python - 如何將dataframe導入到excel且不覆蓋原有內容

瀏覽:89日期:2022-08-09 11:28:23

問題描述

使用了pandas的to_excel方法,但每次都會覆蓋原來的內容。請問還有什么方法可以將dataframe格式的數據導入到excel呢?

問題解答

回答1:

兩種方法選一種:

df.to_csv, 參數mode=’a’表示追加

df.to_excel,在寫入之前把df的值拼在一起寫入,比如原來的數據是df1, 要寫入的數據是df2則 pandas.concat([df1, df2]).to_excel()

回答2:

to_excel支持許多參數,其中:

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

寫入excel文件之前先獲取excel中已使用的行數,to_excel中寫入要開始的行數即可

標簽: python
相關文章:
国产综合久久一区二区三区