I have the following pandas dataframe.
df = pd.DataFrame({'Neighborhood': ['Marble Hill', 'Chelsea', 'Sutton Place'],
'Venue Category': ['Hospital', 'Bridge', 'School']})
When I execute it, I get the following table.
Neighborhood Venue Category
0 Marble Hill Hospital
1 Chelsea Bridge
2 Sutton Place School
Now, I want to assign numerical values for each Venue Category.
Hospital - 5 marks
School - 4 marks
Bridge - 2 marks
So I tried to assign marks using this code. I want to display the marks in a separate column.
def df2(df):
if (df['Venue Category'] == 'Hospital'):
return 5
elif (df['Venue Category'] == 'School'):
return 4
elif (df['Venue Category'] != 'Hospital' or df['Venue Category'] != 'School'):
return np.nan
df['Value'] = df.apply(df2, axis = 1)
Once executed, it gives me the following warning. May I know how to fix this please?
/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/ipykernel_launcher.py:9: 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: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
if __name__ == '__main__':