Home > Net >  Replace specials characters in column
Replace specials characters in column

Time:09-08

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

CodePudding user response:

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

CodePudding user response:

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