python 在一个excel存多个sheet
Posted 明媚的夏午
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()
结果:
以上是关于python 在一个excel存多个sheet的主要内容,如果未能解决你的问题,请参考以下文章