how do you loop faster in pandas? i'm using 2 loops the first loop will loop through the dates and the second loop will loop through the symbols so in every day, I will go through all of the symbol and analyze data from it.
the code below works properly but will go slow once I add more symbols
# self.Price contain multiple symbols
# self.ActiveSymbols contains the string name of the symbol
backtest = pd.concat(self.Price, keys=self.ActiveSymbol,axis=1)
for date in backtest.index:
for symbol in ActiveSymbols:
#compute something......
backtest[symbol].loc[date,'close']
.......
analyzing 1 symbol: time 0.4705786999999999
analyzing 5 symbol: time 3.2083443000000003
.......