Hi When I use the following code I get the following error:
SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df['sic_code'][index] = comp_dict[key]
for index, row in df.iterrows():
for key in comp_dict:
if row['code'] == key:
df['sic_code'][index] = comp_dict[key]
I have tried using the code below which does remove the error but it changes the output of the code so that the changes I want do not occur. To show you what I mean when I use the below code I get which Is wrong when i use the above code (which produces the error) I get
.
for index, row in df.iterrows():
for key in comp_dict:
if row['code'] == key:
df.loc[df['sic_code'][index]] = comp_dict[key]