2017-12-22 7 views
0

를 사용 : 지침에 따라 일부를 수행 한 후 malev/gender-detectorUnicodeDecodeError 때 몇 가지 분석을위한 추측 성별을 할 필요가 있고, 몇 가지 조사 후 내가 GitHub의에서이 파이썬 라이브러리를 발견했습니다 특정 파이썬 라이브러리 (성 검출기)

미 조정 (예 : 추가 정보는 import gender_detector as gd 지시하지만 난이, '우리', '영국', '아칸소' '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로 파일을 열었고 변경없이 저장했지만 LibreOffice는 utf-8 인코딩은 이제 작동합니다. –