I am trying to replace values in the 'mapped' dataframe with mappings in 'mappings' dataframe.
for column in df:
mapped[column] = df[column].astype(str)
for i, row in mappings.iterrows():
coln = row['colname']
val = row['value']
map = row['mapping']
print 'match::' + coln + ":"+str(val)+ ":"+str(map)
print mapped[mapped[coln]== val]
mapped[coln].replace(str(val), str(map))
print mapped.head()
Although there are matching records, the values in 'mapped' dataframe is not getting replaced. How can I fix this?
replaceis not aninplaceoperation by default. You must assign the changes back to the column of interest. So -mapped[coln].replace(str(val), str(map), inplace=True)