簡體   English   中英

Python utf8編解碼器無法解碼位置103的字節0x80:無效的起始字節

[英]Python utf8 codec can't decode byte 0x80 in position 103:invalid start byte

這是我的代碼和我的csv文件的示例,運行代碼后,錯誤顯示utf8編解碼器無法解碼位置103的字節0x80:無效的起始字節,並且有人可以幫助 這是文件的例子

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')

我在此代碼上有錯誤,但我不知道為什么會顯示錯誤

這是unicode轉換錯誤,請嘗試...

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM