I execute the following code on the Python DataFrame "restaurants":
italian_restaurants = restaurants[restaurants['Cuisine']=='Italian']
italian_restaurants.rename(columns = {'Total restaurants':'Italian restaurants'}, inplace = True)
And the response is the following warning:
/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py:4125: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
return super().rename(
How can I rewrite the code to avoid the warning? The problem seems to verse around the idea that I am copying the slice into a new DataFrame, but I cannot find the solution.
Thank you for your help!