I am trying to execute the below code.
# Run momentum routine every month of valid data and store results
#Initialize the results dataframes
results_EW = pd.DataFrame(np.zeros((portfolios*T, T+lead-1)))
results_VW = pd.DataFrame(np.zeros((portfolios*T, T+lead-1)))
for t in range(0,len(month_list),1):
EW=pd.DataFrame()
VW=pd.DataFrame()
monthno=month_list[t]
EW,VW = moment(monthno,portfolios,lead)
for port in range(1,portfolios+1,1):
portval="P"+str(port)
results_EW.loc[(port-1)*T+t,t:t+lead-1]=EW.loc[portval,:].values.tolist()
results_VW.loc[(port-1)*T+t,t:t+lead-1]=VW.loc[portval,:].values.tolist()
I keep on getting the below error: enter image description here
A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
This is added back by InteractiveShellApp.init_path()
C:\Users\teju\anaconda3\lib\site-packages\pandas\core\indexing.py:1597: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy self.obj[key] = value C:\Users\teju\anaconda3\lib\site-packages\pandas\core\indexing.py:1676: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
Can someone please help how to resolve this error?