使用了pandas的to_excel方法,但每次都會(huì)覆蓋原來(lái)的內(nèi)容。
請(qǐng)問(wèn)還有什么方法可以將dataframe格式的數(shù)據(jù)導(dǎo)入到excel呢?
認(rèn)證0級(jí)講師
兩種方法選一種:
df.to_csv, 參數(shù)mode='a'表示追加
df.to_excel,在寫(xiě)入之前把df的值拼在一起寫(xiě)入,比如原來(lái)的數(shù)據(jù)是df1, 要寫(xiě)入的數(shù)據(jù)是df2
則 pandas.concat([df1, df2]).to_excel()
to_excel支持許多參數(shù),其中:
startrow :
upper left cell row to dump data frame
startcol :
upper left cell column to dump data frame
寫(xiě)入excel文件之前先獲取excel中已使用的行數(shù),to_excel中寫(xiě)入要開(kāi)始的行數(shù)即可
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)