Python utf8编解码器无法解码位置103的字节0x80:无效的起始字节

时间:2018-09-03 09:02:42

标签: python utf-8 decode opencsv

这是我的代码和我的csv文件的示例,运行代码后,错误显示utf8编解码器无法解码位置103的字节0x80:无效的起始字节 以及是否有人可以帮助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 :(得分:0)

这是Unicode转换错误,请尝试...

h = pd.read_csv('C:/Users/Desktop/Result.csv',编码=“ utf-8”)