I want to replace values in a pandas Series using a dictionary. I'm following @DSM's accepted answer like so:
s = Series(['abc', 'abe', 'abg'])
d = {'b': 'B'}
s.replace(d)
But this has no effect:
0 abc
1 abe
2 abg
dtype: object
The documentation explains the required format of the dictionary for DataFrames (i.e. nested dicts with top level keys corresponding to column names) but I can't see anything specific for Series.
inplace=Truee.g.s = s.replace(d)ors.replace(d, inplace=True), virtually all pandas ops return a copy so you either want to assign back or passinplace=Truewhere supporteds.replace(d, regex=True)s.replace(d, inplace=True)- doesn't do desired replacement - test it...