我有一个数据集,其中包括一列文字(歌词)。
有时在文本中会有一些单词(或符号)没有被正确解码,这里是一个例子。
'I keep trying Ainâ\\x80\\x99t no denyingWe should be together nowI canâ\\x80\\x99t imagineYouâ\\x80\\x99re with another man Baby'
我想用regex找到所有这些子串,但我不知道模式是否相同(一个字母,两个反斜杠,x加上两个数字)
还是有一些简单的编码参数,"读取 "所有的字符?
谢谢你的帮助!我有一个数据集,其中包括一列文本(歌词)。
如果我的问题是正确的,你需要找到正确的文件编码。
像这样找到文件的编码。
# import the chardet library
import chardet
# use the detect method to find the encoding
# 'rb' means read in the file as binary
with open(your_file, 'rb') as file:
print(chardet.detect(file.read()))
这个片段将打印出正确的文件编码,如下图:
{'encoding': 'UTF-16', 'confidence': 1.0, 'language': ''}
现在用正确的编码打开你的文件。
如果你没有安装chardet库。
pip install chardet
希望这能帮助你。