Кодек Python utf8 не может декодировать байт 0x80 в позиции 103: недопустимый начальный байт - PullRequest
0 голосов
/ 03 сентября 2018

Вот мой код и пример моего csv-файла, и после запуска кода появляется ошибка: кодек utf8 не может декодировать байт 0x80 в позиции 103: недопустимый начальный байт и если кто-то может помочь this is the example of the file

import csv
import pandas as pd
import numpy as np
import os
import sys
h = pd.read_csv('C:/Users/Desktop/Result.csv')

sentences = h['Mention']

def check_it(sentences):
    if 'camera' in sentences:
        return "Camera"
    if 'Camera' in sentences:
        return "Camera"

    if 'display' in sentences:
        return "Display"
    if 'Display' in sentences:
        return "Display"

    if 'battery' in sentences:
        return "Battery"
    if 'Battery' in sentences:
        return "Battery"

    if 'temperature' in sentences:
        return "Temperature"
    if 'Temperature' in sentences:
        return "Temperature"

    if 'memory' in sentences:
        return "Memory"
    if 'Memory' in sentences:
        return "Memory"

    if 'audio' in sentences:
        return "Audio"
    if 'Audio' in sentences:
        return "Audio"

    if 'design' in sentences:
        return "Design"
    if 'Design' in sentences:
        return "Design"

    return "Others"

h.loc[:, 'Category'] = h.Mention.apply(check_it)

h.to_csv('C:/Desktop/ResultWithCategory.csv')

Я получил ошибку в этом коде, и я не знаю, почему ошибка появляется

1 Ответ

0 голосов
/ 03 сентября 2018

Это ошибка преобразования юникода, попробуйте это ...

h = pd.read_csv ('C: /Users/Desktop/Result.csv', encoding = "utf-8")

...