when I run this code below, I get the right result, apparently, but I also get the error in the title. I checked the other similar questions but I cannot relate them to my case
df_zinc['buy_sell'] = 0
index = 0
while index < df_zinc.shape[0]:
if df_zinc['action'][index] == 1:
if df_zinc['PX_LAST'][index]<df_zinc['ma'][index]:
df_zinc.loc[index,'buy_sell'] = -1
else:
df_zinc.loc[index,'buy_sell'] = 1
if df_zinc['action'][index] == -1:
df_zinc['buy_sell'][index] = df_zinc['buy_sell'][index-avg_window]*-1
index=index+1
df_zinc.buy_sell.value_counts()