问题遇到的现象和发生背景
你好 我想将以下的代码运行时间缩短。谢谢!
操作环境、软件版本等信息
start_date='2023-08-08'
end_date='2024-09-08'
date_index=pd.date_range(start_date,end_date)
IndustryRotate=pd.DataFrame()
IndustryName=w.wset("sectorconstituent","date="+end_date+";sectorid=a39901011g000000",usedf=True)[1]
IndustryName=IndustryName['wind_code'].tolist()
for i in range(len(date_index)):
date=date_index[i]-timedelta(days=1)
date=date.strftime('%Y-%m-%d')
date2=date_index[i]
date2=date2.strftime('%Y-%m-%d')
IndustryNamePct=w.wss(IndustryName, "pct_chg","tradeDate="+date+";cycle=D",usedf=True)[1]
IndustryNamePct['Rank']=IndustryNamePct['PCT_CHG'].rank()
IndustryNamePct.dropna(inplace=True)
if len(IndustryNamePct)==0:
continue
IndustryNamePct2=w.wss(IndustryName, "pct_chg","tradeDate="+date2+";cycle=D",usedf=True)[1]
IndustryNamePct2['Rank2']=IndustryNamePct2['PCT_CHG'].rank()
IndustryNamePct2.dropna(inplace=True)
if len(IndustryNamePct2)==0:
continue
IndustryNamePctT=pd.concat([IndustryNamePct['Rank'], IndustryNamePct2['Rank2']], axis=1)
IndustryNamePctT['Diff']=abs(IndustryNamePctT['Rank']-IndustryNamePctT['Rank2'])
Sum=IndustryNamePctT['Diff'].sum()
IndustryRotate=IndustryRotate.append(pd.DataFrame({'Date':[date_index[i]],'RankSum':[Sum]}),ignore_index=True)
print(IndustryRotate)
我想要达到的结果
缩短代码运行时间