python 在一個excel存多個sheet


import pandas as pd
import numpy as np
import os
from sqlalchemy import create_engine


def get_station_weather(sql_engine,sid):
data = pd.read_sql_query(
"SELECT Station_Id_c, WIN_D_Avg_10mi, TimeStamp, WIN_S_Avg_10mi FROM Weather_Station_Hour "
" where Station_Id_c='%s'ORDER BY TimeStamp"% (sid),sql_engine)
return data


if __name__ == '__main__':

sql_engine = create_engine('mssql+pymssql://**********************')

#——————————————————————————玉林小時風速風向————————————————————————————
yulin_station_id=['59449','59457','59451','59452']
writer = pd.ExcelWriter('/data01/home/gzblue/xgx/weizhan/yulin_weather.xlsx')
for sid in yulin_station_id:
station_59449 = get_station_weather(sql_engine,sid=sid)
print(station_59449)
station_59449.to_excel(excel_writer=writer,sheet_name=sid)
writer.save()
writer.close()


結果:

 





免責聲明!

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



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