remove control character whitespaces from dataframe
<p>I have a dataframe df by which I am getting list of list by using this</p>

<pre><code>data = [list(map(str,n.tolist())) for n in df.values]
</code></pre>

<p>after that I replace specific control character from data like this </p>

<pre><code>data = [ [e.replace(u'\xa0', u'') for e in tempval ] for tempval in data ]
</code></pre>

<p>This works fine but I want this to be done in dataframe itself  please suggest something.</p>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html" rel="nofollow"><code>DataFrame.replace</code></a>:</p>

<pre><code>df = pd.DataFrame({'A':['\xa0','s','w'],
                   'B':['s','w','v'],
                   'C':['e','d','\xa0']})

print (df)
   A  B  C
0     s  e
1  s  w  d
2  w  v  
</code></pre>

<p>Then for creating <code>list</code> of <code>lists</code> convert <code>DataFrame</code> to <code>numpy array</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.values.html" rel="nofollow"><code>values</code></a> and then <code>tolist</code>:</p>

<pre><code>df.replace(u'\xa0',u'', regex=True, inplace=True)
#if need cast all values to str add astype
print (df.astype(str).values.tolist())
[['', 's', 'e'], ['s', 'w', 'd'], ['w', 'v', '']]
</code></pre>

python list pandas replace dataframe