我有一个 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的案例。 我的目标是通过以正确的顺序进行解码和编码,以编程方式修复损坏的字符。
您面临双重 mojibake 情况(Python 中的示例): 'FrÌchette|Fran̤ois'.encode( 'cp1252').decode( 'mac-romanian').encode( 'cp1252').decode( 'utf -8') 返回 'Fréchette|François'。
Mojibake感谢对这个问题提供的非常有帮助的意见,我们已经确定这确实是
读取当前未指定编码的csv
这里是经过上述重新编码后仍然损坏的字符列表:
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的过程中丢失了)。恐怕这些线路必须手动修复。