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

问题描述 投票:0回答:1

这是我的代码和我的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')

我在这段代码上遇到错误,我不知道错误出现的原因

python utf-8 decode opencsv
1个回答
0
投票

这是unicode转换错误,试试这个......

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

© www.soinside.com 2019 - 2024. All rights reserved.