Unicodedecodeerror: 'utf-8' Codec Can't Decode Byte 0x96 In Position 15: Invalid Start Byte
import csv import pandas as pd db = input('Enter the dataset name:') table = db+'.csv' df = pd.read_csv(table) df = df.sample(frac=1).reset_index(drop=True) with open(table,'rb') a
Solution 1:
You need to check encoding of your csv
file.
For that you can use print(f)
like this,
withopen('file_name.csv') as f:
print(f)
The output is something like this:
<_io.TextIOWrappername='file_name.csv'mode='r'encoding='utf8'>
Open csv
with that encoding like this,
withopen(fname, "rt", encoding="utf8") as f:
As mentioned in comments,
your encoding is cp1252
so,
withopen(fname, "rt", encoding="cp1252") as f:
...
and for .read_csv
,
df = pd.read_csv(table, encoding='cp1252')
Post a Comment for "Unicodedecodeerror: 'utf-8' Codec Can't Decode Byte 0x96 In Position 15: Invalid Start Byte"