Skip to content
Advertisement

Warning while adding rank column to a pandas dataframe

I have derived a dataframe using groupby.

I am trying to set a new column ‘rank’ based on the ‘volume’ column using the below code.

The code is working but giving a warning –

JavaScript

Below is my code. Would appreciate guidance as I am not too much experienced in Python/ Pandas.

JavaScript

Advertisement

Answer

Because after you filter your dataframe and assign to another variable name even if you use loc you are still using a shallow copy. In order to not get the warning you should copy the dataframe properly like this.

JavaScript
Advertisement