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>Solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.replace.html" rel="nofollow"><code>replace</code></a> by <code>dictionary</code>:</p>

<pre><code>df['prod_type'] = df['prod_type'].replace({'respon':'responsive', 'r':'responsive'})
print (df)
    prod_type
0  responsive
1  responsive
2  responsive
3  responsive
4  responsive
5  responsive
6  responsive
</code></pre>

<p>If need set all values in column to some <code>string</code>:</p>

<pre><code>df['prod_type'] = 'responsive' 
</code></pre>

python string python-2.7 pandas replace