I have a DataFrame that looks like this:
What I want is to compute the following operation, described in a loop:
for ii in range(0,len(df['Avg'])):
if ii==0:
df['Return'][ii]=0
else:
df['Return'][ii] = (df['Avg'][ii])/(df['Avg'][ii-1])-1
I want to use 'present' and 'previous' element from 'Avg' column to make that operation, but I'm getting this error:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy df['Return'][ii]=0 C:/Users/julio/Desktop/Python Scripts/Euclid Capital Scripts/DukasCopy/duka_test:34: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy df['Return'][ii] = (df['Avg'][ii])/(df['Avg'][ii-1])-1
Is there another way to achieve what I want and store those values in the 'Return' column?