Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace non breaking spaces \xa0 inside string


I'm writing a script in Python to transfer Excel Online data to GCP and I would like to replace \xa0 from strings inside column of DataFrame like '\xa0shopName' , '\xa0Street Adress', '\xa0'.
I've tried df = df.replace(u'\xa0', u''), but it's only replacing '\xa0', the strings with \xa0 and words stay the same. Maybe regex df = re.sub('#regular expression', '', df)will help, but i cannot find correct regex sentence :/

like image 849
SnakeR Avatar asked Dec 06 '25 16:12

SnakeR


1 Answers

You can use

df = df.replace('\xa0', '', regex=True)

By passing the regex=True option, you trigger re.sub behind the scenes, that replaces all occurrences of non-breaking spaces with an empty string.

like image 194
Wiktor Stribiżew Avatar answered Dec 08 '25 07:12

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!