How to remove carriage return in a dataframe
<p>I am having a dataframe that contains columns named id, country_name, location and total_deaths. While doing data cleaning process, I came across a value in a row that has <code>'\r'</code> attached. Once I complete cleaning process, I store the resulting dataframe in destination.csv file. Since the above particular row has <code>\r</code> attached, it always creates a new row.</p>

<pre><code>id                               29
location            Uttar Pradesh\r
country_name                  India
total_deaths                     20
</code></pre>

<p>I want to remove <code>\r</code>. I tried <code>df.replace({'\r': ''}, regex=True)</code>. It isn't working for me.</p>

<p>Is there any other solution. Can somebody help?</p>

<h3>Edit:</h3>

<p>In the above process, I am iterating over df to see if <code>\r</code> is present. If present, then need to replace. Here <code>row.replace()</code> or <code>row.str.strip()</code> doesn't seem to be working or I could be doing it in a wrong way.</p>

<p>I don't want specify the column name or row number while using <code>replace()</code>. Because I can't be certain that only 'location' column will be having <code>\r</code>. Please find the code below.</p>

<pre><code>count = 0
for row_index, row in df.iterrows():
    if re.search(r"\\r", str(row)):
        print type(row)               #Return type is pandas.Series
        row.replace({r'\\r': ''} , regex=True)
        print row
        count += 1
</code></pre>