Mar-26-2019, 01:04 AM
Applying changes via
your approach is ok. If you need to perform a lot of replacements, it would be better to consider applying some mapping, e.g.
.loc
is quite efficient, I think; If the number of such replacements is not too much, your approach is ok. If you need to perform a lot of replacements, it would be better to consider applying some mapping, e.g.
df.loc[... ...] = df.loc[... ...].map(lambda x: trans.get(x, x))
, where trans
is a dictionary, e.g. trans = {'old_value1': 'new_value1', 'old_value_2': 'new_value2', ...}