Reputation: 1993
I'm trying to have terms in a dataframe, an old term (existing) and a new term that will replace it.
This dataframe is then used in the replace() process. Runnig the following presents a keyerror error KeyError: "None of [Index([('HIS_COP_', ''), ('_Ply', ''), ('_Pt', '')], dtype='object')] are in the [columns]"
Manually this works:
gdf['montype'].replace('HIS_COP_', '', regex=True, inplace=True)
gdf['montype'].replace('_Ply', '', regex=True, inplace=True)
gdf['montype'].replace('_Pt', '', regex=True, inplace=True)
code:
montype = [['HIS_COP_', ''],
['_Ply', ''],
['_Pt','']]
df = pd.DataFrame(montype, columns=['term_old', 'term_new'])
for term in df:
print(df)
gdf[montype].replace(term['term_old'], term['term_new'], regex=True, inplace=True)
Upvotes: 1
Views: 35