I have several pandas dataframes with different accented characters in their column names. I would like to convert accented characters to their unaccented equivalents only in column names. I am looking for similar solutions to which I regularly use in R: names(DT) = stringi::stri_trans_to_general('latin-ASCII', names(DT))
Asked
Active
Viewed 342 times
1 Answers
1
unidecode
can convert accented chars to unaccented versions. Loop it across all the columns like so:
import unidecode
df.columns = [unidecode.unidecode(col) for col in df.columns]

kkawabat
- 1,530
- 1
- 14
- 37
-
1Can also use `df.rename(columns=unidecode.unidecode)` – ifly6 Aug 09 '19 at 18:55
-
It definitely works! I spent 2 hours to google a solution but I haven't got a similar question neither. Thanks! – sanyi Aug 09 '19 at 19:57
-
I'm glad : ) feel free to mark the question as answered. – kkawabat Aug 09 '19 at 21:31