文章詳情頁
python - 如何將dataframe導入到excel且不覆蓋原有內容
瀏覽:100日期: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
上一條:python - pyspider爬取了接近1G的數據,無法導出csv?下一條:python - Django ManyToManyField 字段數據在 admin后臺 顯示不正確,這是怎么回事?
相關文章:
1. MySQL客戶端吃掉了SQL注解?2. php自學從哪里開始?3. mysql - AttributeError: ’module’ object has no attribute ’MatchType’4. 數據庫 - MySQL 單表500W+數據,查詢超時,如何優化呢?5. 求大神幫我看看是哪里寫錯了 感謝細心解答6. python - Django分頁和查詢參數的問題7. javascript - 圖片能在網站顯示,但控制臺仍舊報錯403 (Forbidden)8. javascript - 百度echarts series數據更新問題9. phpstady在win10上運行10. python小白的基礎問題 關于while循環的嵌套
排行榜
