码迷,mamicode.com
首页 > 编程语言 > 详细

python 在一个excel存多个sheet

时间:2019-01-07 17:33:47      阅读:626      评论:0      收藏:0      [点我收藏+]

标签:col   com   alc   分享图片   一个   for   numpy   timestamp   xlsx   

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

标签:col   com   alc   分享图片   一个   for   numpy   timestamp   xlsx   

原文地址:https://www.cnblogs.com/avivi/p/10233918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!