Remove non-ASCII characters from pandas column
<p>I have been trying to work on this issue for a while.I am trying to remove non ASCII characters form DB_user column and trying to replace them with spaces. But I keep getting some errors. This is how my data frame looks:</p>

<pre>

+-----------------------------------------------------------
|      DB_user                            source   count  |                                             
+-----------------------------------------------------------
| ???/"Ò|Z?)?]??C %??J                      A        10   |                                       
| ?D$ZGU   ;@D??_???T(?)                    B         3   |                                       
| ?Q`H??M'?Y??KTK$?Ù‹???Ð©JL4??*?_??        C         2   |                                        
+-----------------------------------------------------------

</pre>

<p>I was using this function, which I had come across while researching the problem on SO.</p>

<pre><code>def filter_func(string):
   for i in range(0,len(string)):


      if (ord(string[i])&lt; 32 or ord(string[i])&gt;126
           break

      return ''

And then using the apply function:

df['DB_user'] = df.apply(filter_func,axis=1)
</code></pre>

<p>I keep getting the error:</p>

<pre>

'ord() expected a character, but string of length 66 found', u'occurred at index 2'
</pre>

<p>However, I thought by using the loop in the filter_func function, I was dealing with this by inputing a char into 'ord'. Therefore the moment it hits a non-ASCII character, it should be replaced by a space.</p>

<p>Could somebody help me out?</p>

<p>Thanks!</p>