I am trying to loop my function by the rows of my dataframe. I am sharing an example of it, actual data consist of about 1000 rows and 8 columns. Is it possibel to run a for loop to get this? I would rather not use "pandas apply"
import pandas as pd
import numpy as np
weights = {'W1': [0.25,0.25,0.25,0.25],
'W2': [0.2,0.2,0.2,0.4],
'W3': [0.2,0.3,0.5,0.0]
}
df = pd.DataFrame(weights, columns = ['W1', 'W2', 'W3'])
ER = np.array([0.08, 0.09, 0.10])
def PortfolioReturn_Calc(weights, ER):
portfolio_ret = (ER * weights).sum(axis=1)
return portfolio_ret
for i in range(len(weights)):
Ws = rows.df
PortfolioReturn_Calc(Ws, ER)