I have the following code but don't quite understand why it is throwing the warning. I have read the documentation but still cannot wrap my head around why this usage would result in the warning. Any insight would be appreciated.
>>> df = pandas.DataFrame({'a': [1,2,3,4,5,6,7], 'b': [11,22,33,44,55,66,77]})
>>> reduced_df = df[df['a'] > 3]
>>> reduced_df
a b
3 4 44
4 5 55
5 6 66
6 7 77
>>> reduced_df['a'] /= 3
Warning (from warnings module):
File "__main__", line 1
SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_index,col_indexer] = value instead
>>> reduced_df
a b
3 1.333333 44
4 1.666667 55
5 2.000000 66
6 2.333333 77