Here is my code and sample of my csv file and after I run the code, the error shows up utf8 codec can't decode byte 0x80 in position 103:invalid start byte and if anyone could help
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')
I got error on this code and I dont know why the error shows up
This is unicode conversion error, try this...
h = pd.read_csv('C:/Users/Desktop/Result.csv', encoding = "utf-8")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.