I'm currently try to understand this warning:
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've seen this alot on SO, however my issue arises when trying to map.
My code is as such:
def merger(df):
qdf = pd.read_csv('domains_only_df.csv')
unfilt_rel_domains = qdf[['name', 'hits', 'owner', 'curated', 'domain']].copy()
rel_domains = unfilt_rel_domains[unfilt_rel_domains['curated'] == 0]
hits_dict= pd.Series(rel_domains.hits.values, index=rel_domains.owner).to_dict()
name_dict = pd.Series(rel_domains.name.values, index=rel_domains.owner).to_dict()
domain_dict = pd.Series(rel_domains.domain.values, index=rel_domains.owner).to_dict()
df['Hits'] = df['eid'].map(hits_dict).fillna(0)
df['Existing_domain'] = df['eid'].map(name_dict).fillna(0)
df['idn'] = df['eid'].map(domain_dict).fillna(0)
return df
The error occurs with .map()
, my question is how would write a mapping using the warning's recommendation of using .loc[row_indexer,col_indexer] = value
? I need .map()
for speed and the lookup but I'm not quite sure how to avoid this warning.