1

I'm very new to Python and need help with a for loop. With the following code, I'm able to generate an array with 12 values of predictor, which is what I want. The thing is I'm trying to generate 1000 arrays of 12 values each and I'm not sure how to proceed. Ideally, I'd like to have a DataFrame with 1000 columns of 12 rows of predictor values, if possible.

Thank you!

df_predictor = []

per = list(range(1,13))

for p in per:
  predictor = phi.iloc[0].values + phi.iloc[1].values * r_train[-1] + phi.iloc[2].values *r_train[-2] + phi.iloc[3].values * r_train[-3] + npr.choice(residuals,size=1,replace=True)
  df_predictor = np.append(df_predictor, predictor)

df_predictor

Here's the output I get:

array([7.85220025, 7.22399331, 7.71090475, 8.25297532, 7.68099532,
       7.78266941, 7.83697048, 7.90080309, 8.26081117, 8.10520116,
       6.2398817 , 7.78395003])```
  • Welcome to Stack Overflow. The code example that you have provided is not yet reproducible. Is phi a pandas dataframe? If so could you provide it as well? – intedgar Nov 17 '21 at 01:33

0 Answers0