Avoiding setting with copy warning
<pre><code>df_n_years = df.iloc[:, -self.num_years - 1:-1]
df_n_years.rename(columns=lambda x: 'VAL_' + str(x), inplace=True)  # results in SettingWithCopyWarning
</code></pre>

<p>I am extracting the last few columns from a dataframe and then renaming them. It does result in a setting with copy warning. I understand why the warning is happening, what's the best way to avoid it?</p>