Wie kann ich Zeichenkodierung einer Datei in utf-8 umwaldeln?

Ich habe eine CSV-Datei, die ich mit Pandas bearbeiten möchte. Der Dateiinhalt enthält Sonderzeichen, die fehlerhaft angezeigt werden. Ich habe versucht, die Datei im UTF-8-Format zu speichern, indem ich sie in einem Editor öffne und unter dieser Codierung abspeichere. Leider hat das nicht geholfen. Die Sonderzeichen werden nur korrekt angezeigt, wenn ich den Inhalt in einem neuen Editor kopiere und dann im UTF-8-Format speichere. Dieser manuelle Prozess ist jedoch für große Dateien unpraktisch. Gibt es eine einfache Methode, dies zu automatisieren? Außerdem suche ich nach einer geeigneten Formel für Pandas, um mit solchen Dateien umzugehen. Kannst du mir dabei helfen?

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
2 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
jo135
1 year ago

iconv can do this (and even more): https://manpages.debian.org/bookworm/manpages/iconv.1.en.html

I also look for a suitable formula for Pandas to deal with such files.

What do you think? You can also explicitly specify the expected encoding of the file:

https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html

tide1109
1 year ago

You can also give Pandas the Encoding. Then you can read UTF-16 files directly.

docu to read_csv(). Here’s the paramter “encoding”.

Gültige Encodings are there in the Doku link.