So I am trying to create a new column in my pandas dataframe based on some conditionals with respect to some other already established columns. The logic in this code is fairly simple.
conditions_home = [premier_league_75['home_goals']>premier_league_75['away_goals'],
premier_league_75['home_goals']<premier_league_75['away_goals'],
premier_league_75['home_goals']==premier_league_75['away_goals']]
values_home = [3,0,1]
premier_league_75['home_points'] = np.select(conditions_home,values_home)
Unfortunately this produces the warning:
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
The resulting new column produces correct results but I am confused why the code is producing a warning. How would I be able to create this new column using these conditionals and not produce this warning?