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

Convert "weird" strings to normal python strings

Context: I’m trying to convert characters like these:

๐๐”๐ˆ๐‹๐ƒ๐ˆ๐๐†
๐™Ž๐™ฅ๐™š๐™š๐™™๐™ฎ
๐•‹๐•Œ๐”ผ๐•Š๐”ป๐”ธ๐•
๐•ค๐•ก๐•’๐•˜๐•™๐•–๐•ฅ๐•ฅ๐•š

To normal python strings (speedy, building, tuesday, etc) and save them into a new dataframe to be exported into a new excel file. For example, the charcter ๐•’ (U+1D552) should be converted to a (U+00AA). I’m reading each string from an excel file using read_excel. Should I do some type of encoding = "utf-8"? on the read_excel function? Or is there a way using re to replace those characters? Or even encode("ascii").decode(utf-8)?

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

Thank you in advance

>Solution :

Using unicodedata you can normalize unicode strings:

>> from unicodedata import normalize
>> test_str = "๐๐”๐ˆ๐‹๐ƒ๐ˆ๐๐† ๐™Ž๐™ฅ๐™š๐™š๐™™๐™ฎ ๐•‹๐•Œ๐”ผ๐•Š๐”ป๐”ธ๐• ๐•ค๐•ก๐•’๐•˜๐•™๐•–๐•ฅ๐•ฅ๐•š"
>> print(normalize('NFKC', test_str))
BUILDING Speedy TUESDAY spaghetti
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