0

Is there a way to optimize the code below ?

data, train_data are dataframe data has almost 1M rows

timesteps = 20
for i in range (0, len(data)):
    for j in range (0, timesteps):
        train_data = train_data.append(data.iloc[i], ignore_index=True)
zitoun
  • 45
  • 3
  • https://stackoverflow.com/questions/22108488/are-list-comprehensions-and-functional-functions-faster-than-for-loops – Joe Apr 12 '20 at 15:31
  • How are you using *j*? Also, using `DataFrame.append` in a for-loop leads to inefficient [quadratic copying](https://stackoverflow.com/a/36489724/1422451). – Parfait Apr 12 '20 at 15:38
  • apparently by using numpy performance could increase. Someone could help by writing an equivalent code using numpy ? – zitoun Apr 12 '20 at 21:43

0 Answers0