I am struggling with locating the cause of a SettingWithCopyWarning.
My original code is as follows:
df1['stcomb'] = df1['secondary'].str.cat(df1['tertiary'],sep='-')
df1['stcomb'] = df1['stcomb'].fillna(df['secondary'])
staffs = {'T1':1, 'T2':2}
df1 = df1.replace(staffs)
numb = {'Y':1,'N':0}
df1 = df1.replace(numb)
df1.head()
It threw 2 SettingWithCopyWarning, both ending with
Try using .loc[row_indexer,col_indexer] = value instead
I attempted doing that and a dozen other modifications, and finally split the code to two Jupyter cells. Each cell throws its own warning.
Cell1
secondary = df1['secondary']
tertiary = df1['tertiary']
comb = secondary + '-' + tertiary
cmb = pd.Series(comb)
df1.insert(3,'stcomb',cmb)
df1['stcomb'].fillna(secondary, inplace=True)
Cell2
staffs = {'T1':1, 'T2':2}
df1.replace(staffs, inplace=True)
numb = {'Y':1,'N':0}
df1.replace(numb, inplace=True
After the link to the pydata caveats page, the warnings end with:
self._update_inplace(new_data)
and
method=method,
My code works, and the results are what was expected, but I feel like I need to understand this copy vs view business, and, frankly, its getting more unclear.
How should I understand this? Thanks!