I want to replace some values in a column of a dataframe using a dictionary that maps the old codes to the new codes.
di = dict( { "myVar": {11:0, 204:11} } )
mydata.replace( to_replace = di, inplace = True )
But some of the new codes and old codes overlap. When using the .replace method of the dataframe I encounter the error 'Replacement not allowed with overlapping keys and values'
My current workaround is to replace replace the offending keys manually and then apply the dictionary to the remaining non-overlapping cases.
mydata.loc[ mydata.myVar == 11, "myVar" ] = 0
di = dict( { "myVar": {204:11} } )
mydata.replace( to_replace = di, inplace = True )
Is there a more compact way to do this?