data_test
is data frame. data_test.loc[dates]
is data frame too. So, you need to insert array of data frames into column (moreover, of the original data frame). This will consume a lot of memory, at least. You can store obtained data frames in another list. Another way is to save only indices, e.g.
data_test.loc[dates].index.tolist()
. Or, may be, I misunderstood something...Try this:# somewhere before while loop: data_test_ = data_test.copy() # in the while loop, instead of `print(data_test...)` data_test_.loc[end, 'NEW_COLUMN'] = data_test.loc[dates].index.tolist() # or even data_test_.loc[end, 'NEW_COLUMN'] = data_test.loc[dates] # Finally, outside while loop: data_test = data_test_