2017-12-22 14 views
0

を使用して:指示に従って、いくつかを行った後malev/gender-detectorUnicodeDecodeErrorときに私はいくつかの分析のための推測性別を行う必要があり、そしていくつかの研究の後、私はgithubの上で、このPythonライブラリを見つけた特定のPythonライブラリ(男女検出器)

微調整(例えばReadmeにはimport gender_detector as gd指示が、私は、これは、「私たちは」、「英国」は、Ar「は」「UY」libには4つのデータセットを持って、たまたまその後 from gender_detector import gender_detector as gd

を行うために必要ですが、「私たちを使用している場合にのみ機能します'または' uk '

以下の例を参照してください。

from gender_detector import gender_detector as gd 
detector = gd.GenderDetector('us') 
detector2 = gd.GenderDetector('ar') 

detector.guess('Marcos') 
Out[25]: 'male' 

detector2.guess('Marcos') 
Traceback (most recent call last): 

File "", line 1, in 
detector2.guess('Marcos') 

File "/home/cpneto/anaconda3/lib/python3.6/site-packages/gender_detector/gender_detector.py", line 25, in guess 
initial_position = self.index(name[0]) 

File "/home/cpneto/anaconda3/lib/python3.6/site-packages/gender_detector/index.py", line 19, in call 
self._generate_index() 

File "/home/cpneto/anaconda3/lib/python3.6/site-packages/gender_detector/index.py", line 25, in _generate_index 
total = file.readline() # Omit headers line 

File "/home/cpneto/anaconda3/lib/python3.6/codecs.py", line 321, in decode 
(result, consumed) = self._buffer_decode(data, self.errors, final) 

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 1078: invalid continuation byte 

これはpy2対py3の互換性のために起こると私は信じていますが、私はそれについては分かりませんし、これを解決する方法を知りません。

提案がありますか?

答えて

0

ライブラリーでは、arファイルがUTF-8でエンコードされていると想定していますが、それはそうではありません(したがって、byte 0xf1 in position 1078エラー)。ファイルをUTF-8に変換するか、実際のエンコーディングをライブラリに渡す方法を見つける必要があります。

+0

ありがとう、エリック!私はデータセットが "〜/ anaconda3/lib/python3.6/site-packages/gender_detector/dat a"に保存された.csvであることを発見しました。その後、LibreOfficeでファイルを開き、変更なしで保存しました。私のためのutf-8エンコーディング、今それは動作します。 –

関連する問題