python操作Excel將數據寫入多個sheet


將一個列表數據寫入output.xlsx的a,b,c……等sheet中

import pandas as pd
df1 = pd.DataFrame({'a':[3,1],'b':[4,3]})  
df2 = df1.copy()
with pd.ExcelWriter('F:\\python入門\\數據2\\output.xlsx') as writer:
    str1 = ['a','b','c','d','e','f','g','h','i',\
            'j','k','l','m','n','o','p','q']
    for i in str1:
        name = str(i)
        df1.to_excel(writer, sheet_name= name)
writer.save()
writer.close()

結果:

 

 此時每個sheet的內容都是一樣的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM