Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

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

>Solution :

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()})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading