Replace values in pandas Series with dictionary
<p>I want to replace values in a pandas <code>Series</code> using a dictionary. I'm following @DSM's <a href="http://stackoverflow.com/questions/20250771/remap-values-in-pandas-column-with-a-dict">accepted answer</a> like so:</p>

<pre><code>s = Series(['abc', 'abe', 'abg'])
d = {'b': 'B'}
s.replace(d)
</code></pre>

<p>But this has no affect:</p>

<pre><code>0    abc
1    abe
2    abg
dtype: object
</code></pre>

<p>The <a href="http://nipy.bic.berkeley.edu/nightly/pandas/doc/generated/pandas.Series.replace.html" rel="nofollow">documentation</a> explains the required format of the dict for <code>DataFrames</code> (i.e. nested dicts with top level keys corresponding to column names) but I can't see anything specific for <code>Series</code>.</p>

<p>You can do it using <code>regex=True</code> parameter:</p>

<pre><code>In [37]: s.replace(d, regex=True)
Out[37]:
0    aBc
1    aBe
2    aBg
dtype: object
</code></pre>

<p>As you have already <a href="http://stackoverflow.com/questions/40075106/replace-values-in-pandas-series-with-dictionary/40075212#comment67423617_40075106">found out yourself</a> - it's a RegEx replacement and it won't work as you expected:</p>

<pre><code>In [36]: s.replace(d)
Out[36]:
0    abc
1    abe
2    abg
dtype: object
</code></pre>

<p>this is working as expected:</p>

<pre><code>In [38]: s.replace({'abc':'ABC'})
Out[38]:
0    ABC
1    abe
2    abg
dtype: object
</code></pre>

python pandas dictionary replace