拿数据
import time
date = time.strftime("%Y-%m-%d")
date = date.replace("'", "")
from WindPy import *
import pandas as pd
import numpy as np
from pymongo import MongoClient
w.start()
w.isconnected()
import time
from concurrent.futures import ProcessPoolExecutor,ThreadPoolExecutor, as_completed
import json
host ='xxx.1xx.x.2x'
port='27017'
user='xxxx'
code='xxxxxxxx'
uri= "mongodb://"+user+":"+code+"@"+host+":"+port+"/"+"?authMechanism=SCRAM-SHA-1"
client=MongoClient(uri)
db = client['Test']#db
collection = db['Wind_A_list']#collection
A_list = w.wset("sectorconstituent","date=2019-07-30;sectorid=a001010100000000",usedf=True)
A_list = A_list[1]#取dataframe部分
collection.drop()#清除collection
collection.insert_many(json.loads(A_list.T.to_json()).values())
df = pd.DataFrame(columns = ['wind_code','close','volume','amt','total_shares'] )
df['wind_code'] = A_list['wind_code']
df_list = A_list.copy()
多线程
def applyParallel(dfGrouped, func):
ppe = ThreadPoolExecutor(10)#设置线程池中最多能同时运行的线程数目
futures = []
results = []
for name, group in dfGrouped:
p = ppe.submit(func, group)#提交函数和变量,立即返回
futures.append(p)
for future in as_completed(futures):
r = future.result()
results.append(r)
return pd.concat(results)#合并表
collection = db['Wind_Data_Fundamental_Quarterly']
collection.drop()
collection = db['Wind_Data_Raw_Price_Daily']
collection.drop()
collection = db['Wind_Data_Adjust_Price_Daily']
collection.drop()
def get_price(df_list):
stk = df_list['wind_code'].iloc[0]
collection = db['Wind_Data_Fundamental_Quarterly']
try:
#取报表数据
data1 = w.wss(stk, "tot_assets,tot_liab,tot_cu