Iloc and Loc | Python
python - pandas: operations using groupby yield SettingWithCopyWarning - let's have following pandas dataframe: df = pd.dataframe({ 'team': ['warriors', 'warriors', 'warriors', 'rockets', 'rockets'], 'player': ['stephen curry', 'klay thompson', 'kevin durant', 'chris paul', 'james harden']}) when try group on team column , perform operation settingwithcopywarning : for team, team_df in df.groupby(by='team'): # team_df = team_df.copy() # produces no warning team_df['rank'] = 10 # produces warning team_df.loc[:, 'rank'] = 10 # produces warning settingwithcopywarning: value trying set on copy of slice dataframe. try using .loc[row_index,col_indexer] = value instead df_team['rank'] = 10 if uncomment line generating copy of sub-dataframe, don't error. Iloc and loc are two important concepts when it comes to website accessibili...