anonymus
anonymus

Reputation: 49

No replacement done after , replace(u'\xa0', u' ', regex=True) in Pandas

I am trying to replace \xa0 with null in Pandas. But No luck. How to get it right ?

Input: {'Team': 'ABE', 'country': 'USA', 'region': '\xa0Texas'}

Code : df1['area'] = df1['area'].replace(u'\xa0', u' ', regex=True)

Output:{'Team': 'ABE', 'country': 'USA', 'region': '\xa0Texas'}

Expected_Output:{'Team': 'ABE', 'country': 'USA', 'region': 'Texas'}

Upvotes: 1

Views: 98

Answers (1)

jezrael
jezrael

Reputation: 863301

I think here is dictionary in column, so you need to dictionary comprehension for replacement:

df1['area']=df1['area'].apply(lambda x: {k: v.replace(u'\xa0', u' ') for k, v in x.items()})

Upvotes: 1

Related Questions