错误(双)编码的 CSV 的反向传播

问题描述 投票:0回答:1

我有一个 CSV 文件,有人编码错误。

该文件是具有相应演员的电影数据库。我下载它是为了练习一些所谓的“培根数”的编码。 看起来像这样:

movieId,title,actors (...) 61,Eye for an Eye (1996),(a ton of other actors)|Dolores VelÌÁzquez|(more actors) 59,The Confessional (1995),(a ton of other actors)|Richard FrÌ©chette|Fran̤ois Papineau|Marie Gignac|Normand Daneau|Anne-Marie Cadieux|Suzanne ClÌ©ment|Lynda Beaulieu|Pascal Rollin|Billy Merasty|Paul HÌ©bert|Marthe Turgeon|Adreanne Lepage-Beaulieu|AndrÌ©e-Anne ThÌ©roux-Faille|Rodrigue Proteau|Philippe Paquin|Pierre HÌ©bert|Nathalie D'Anjou|Danielle Fichaud|Jules Philip|Jacques Laroche|Claude-Nicolas Demers|Jean-Philippe CÌ«tÌ©|Tristan Wiseman|Marc-Olivier Tremblay|Jacques Brouillet|Jean-Paul L'Allier|Denis Bernard|RenÌ©e Hudon|Serge Laflamme|Carl Mathieu (...)

现在如您所见,演员不再使用变音符号和带有重音符号的字母(äÖÜ、É、À、Û 等),而是使用其他特殊字符的组合。

感谢对这个问题提供的非常有帮助的意见,我们已经确定这确实是

Mojibake

的案例。 我的目标是通过以正确的顺序进行解码和编码,以编程方式修复损坏的字符。

python csv encoding utf-8 mojibake
1个回答
0
投票

您面临双重 mojibake 情况(Python 中的示例): 'FrÌchette|Fran̤ois'.encode( 'cp1252').decode( 'mac-romanian').encode( 'cp1252').decode( 'utf -8') 返回 'Fréchette|François'。

感谢对这个问题提供的非常有帮助的意见,我们已经确定这确实是
Mojibake

的案例。 我通过以下配置(python)取得了进展:

读取当前未指定编码的csv
  1. 编码('cp1252').解码('mac-roman').编码('cp1252').解码('iso-8859-16')
  2. 将结果写入指定编码“iso-8859-16”的新 csv
  3. 通过此配置,许多字符现在已修复,但有些字符仍然缺失。我不知道这是否意味着我必须再次解码和编码(总共三次),或者我只是还没有找到一组两个 dec-enc 的正确配置。

这里是经过上述重新编码后仍然损坏的字符列表:

after re-encoding | just reading | desired outcome | notes ============================================================================== � | Ì | Á | the lower case á works; �_ | Ì_ | ü | the upper case Ü works �_ | Ì_ | ä | I can't confirm whether upper case Ä works | æ | I can't confirm whether this exists, but I confirmed one upper case that works; it's possible the file uses 'ae' instead | œ | I can't confirm whether any of this exists; it's possible the file uses 'oe' instead �_ | Ì_ | í | I can't confirm whether upper case Í works �_ | Ì_ | ó | the upper case Ó works �_ | Ì_ | þ | the upper case Þ doesn't exist, I think

结论:

如您所见,“按原样”读取文件以及重新编码后读取文件,都会将所有丢失的字符呈现为“相同”损坏的字符,因此似乎不可能恢复这些字符的原始信息(信息在Mojibake的过程中丢失了)。恐怕这些线路必须手动修复。

© www.soinside.com 2019 - 2024. All rights reserved.