0

When I apply this condition to my output (y). It is giving me this error in Jupyter Notebook.

Condition

conditions = [
    (df['Please mention your Previous Semester GPA?'] < 2.3),
    (df['Please mention your Previous Semester GPA?'] >= 2.3) & (df['Please mention your Previous Semester GPA?'] < 3),
    (df['Please mention your Previous Semester GPA?'] >= 3)
]

values = ['High Chances of Bad Marks', 'Average Marks', 'High Chances of Good Marks']

df['Results'] = np.select(conditions, values)

y=df['Results']
y

Error

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
  df['Results'] = np.select(conditions, values)
  • 2
    Must be something specific to the server your notebooks is on. This code works on my machine. [This post](https://stackoverflow.com/questions/32573452/settingwithcopywarning-even-when-using-locrow-indexer-col-indexer-value) suggests grabbing a `.copy()` of the data first. There are workarounds for you `np.select` statement that involve setting each condition individually – Chris Broz May 24 '22 at 21:05
  • 1
    I've got the same as Chris, seems to work fine on my juptyer notebook. – Liam May 24 '22 at 21:11

0 Answers0