I have the following operation over a Pandas DataFrame in my Python script:
a['tier_diff'] = a['tier_rate'].diff()
discontinuity = a.loc[a['tier_diff'] > 1]
which causes the following warning message:
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
I followed this answer aiming to avoid it, getting the code like this:
a.loc['tier_diff'] = a['tier_rate'].diff()
discontinuity = a.loc[a['tier_diff'] > 1]
but now I get this error: KeyError: 'tier_diff'
Can't find what I missed applying the answer