美文网首页
python积累7(wind api取数据)

python积累7(wind api取数据)

作者: 黄yy家的jby | 来源:发表于2019-02-26 14:56 被阅读0次
    import pandas as pd
    import os
    os.chdir('C:\\Users\\jiangbaiyan\\Desktop\\找到行业的成分股')
    os.getcwd()  
    
    from WindPy import *
    w.start()
    
    industry = pd.read_excel('非重复行业.xlsx')
    industry.columns = ['简称','数据库用','api用']
    industry_list = list(industry['api用'])
    
    #取目标行业的成分股
    dic = {}
    date = '20190102'
    for sector in industry_list:    
        print(sector)
        dic[sector] = w.wset('sectorconstituent', u'date={};sectorid={}'.format(date, sector)).Data[2]
    
    #取目标行业成分股的年涨跌幅和市值
    dic_pct = dic.copy()
    for sector in dic:
        temp = dic[sector]
        dic_pct[sector] = {}
        for stock in temp:
            dic_pct[sector][stock] = w.wsd(stock, "pct_chg",  "2006-01-02", "2019-02-22", "Period=Y").Data[0]
            dic_pct[sector][stock].append((w.wss(stock, "mkt_cap_ard","unit=1;tradeDate=20190225")).Data[0][0])
            print(stock)
        pd_temp = pd.DataFrame(dic_pct[sector]).T
        pd_temp.columns = ['2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','市值']
        dic_pct[sector] = pd_temp
        print(sector,'ok!!!!!!!!!!')
    np.save('wind的api取个股信息.npy',dic_pct)
    
    #分sheet保存
    writer = pd.ExcelWriter('wind的api取.xlsx')
    for key in dic_pct:
        temp = dic_pct[key]
        temp.to_excel(writer,sheet_name = key)
        print(key)
    writer.save()
    

    相关文章

      网友评论

          本文标题:python积累7(wind api取数据)

          本文链接:https://www.haomeiwen.com/subject/mgvayqtx.html