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

Time:03-02

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'}

CodePudding user response:

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()})
  • Related