我有两个数据帧。一个包含在NSE上列出的股票的价格,股票代码作为列名,日期作为索引。另一张包含500只可交易股票的表格(每天都有不同的股票)。我正在尝试创建第三个Dataframe,它将从第一个DF获取数据并将其映射到500个股票。
范围内x的test_portfolio=pd.DataFrame(columns="Stock"+str(x+1) (531),index=df2.index)
Num_col=len(df2.column)
num_row=len(df2)
对于范围内的r(Num_row):
for c in range(num_col): test_portfolio.iat[r,c]=final[df2.iloc[r][c]][r]返回test_portfolio
这个循环占用了太多的时间。有没有办法将其矢量化或减少所需的时间?

发布于 2021-09-01 13:56:33
我认为使用merge会更合适。看一下:https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html
https://stackoverflow.com/questions/68985349
复制相似问题