How to remove accent in Python?

Asked

Viewed 15,237 times

1

In R I would accomplish this way iconv('Arapeí', to="ASCII//TRANSLIT"), so, there’s some simple way to do this in Python?

  • 1

    Please avoid long discussions in the comments; your talk was moved to the chat - About votes, there is a brief explanation in the [Tour], and has more details to understand how the chat works in [Help]. - Also, as regards duplicates, what determines the closure are the responses covering the situations (in the case mentioned, there is a reply there that mentions exactly the unit.

2 answers

11


Use unidecode:

$ pip install unidecode

from unidecode import unidecode
print(unidecode('Arrepieí'))
Arrepiei

str1 = 'café'
print(unidecode(str1))
cafe

4

Use unidecode:

from unicodedata import normalize

source = 'Arapeí'
target = normalize('NFKD', source).encode('ASCII','ignore').decode('ASCII')
print(target)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.