Replace specials characters in column

Viewed 43
name company
Mark Amazon’s Logistics
import pandas as pd
df['company'] = df['company'].str.replace(r"Â|Â|¢|™", "", regex=True) 

This doesn't replace anything.

I want Amazon's Logistics

2 Answers

You can just encode to ascii, and again decode to ascii which will essentially remove all non-ascii characters

>>> df['company'].str.encode('ascii', 'ignore').str.decode('ascii')
0    Amazons Logistics
Name: company, dtype: object

You can create a string with the unwanted characters and iterate .replace :

string = ['’']
for c in string : df  = df['company'].replace(c, "", regex=True)
Related