pandas: replace string with another string
<p>I have the following data frame</p>

<pre><code>    prod_type
0   responsive
1   responsive
2   respon
3   r
4   respon
5   r
6   responsive
</code></pre>

<p>I would like to replace <code>respon</code> and <code>r</code> with <code>responsive</code>, so the final data frame is</p>

<pre><code>    prod_type
0   responsive
1   responsive
2   responsive
3   responsive
4   responsive
5   responsive
6   responsive
</code></pre>

<p>I tried the following but it did not work:</p>

<pre><code>df['prod_type'] = df['prod_type'].replace({'respon' : 'responsvie'}, regex=True)
df['prod_type'] = df['prod_type'].replace({'r' : 'responsive'}, regex=True)
</code></pre>

<p>You don't need to pass <code>regex=True</code> here, as this will look for partial matches, as you''re after exact matches just pass the params as separate args:</p>

<pre><code>In [7]:
df['prod_type'] = df['prod_type'].replace('respon' ,'responsvie')
df['prod_type'] = df['prod_type'].replace('r', 'responsive')
df

Out[7]:
    prod_type
0  responsive
1  responsive
2  responsvie
3  responsive
4  responsvie
5  responsive
6  responsive
</code></pre>

python string python-2.7 pandas replace