Replace values in a pandas series via dictionary efficiently
One trivial solution is to choose a method dependent on an estimate of how completely values are covered by dictionary keys. General case Use df[‘A’].map(d) if all values mapped; or Use df[‘A’].map(d).fillna(df[‘A’]).astype(int) if >5% values mapped. Few, e.g. < 5%, values in d Use df[‘A’].replace(d) The “crossover point” of ~5% is specific to Benchmarking below. … Read more