2
votes

I am using python 3.7 and was trying to import a dataset (csv) using PANDAS When i execute the following code, i get an error which says

'utf-8' codec can't decode byte 0xb5 in position 10: invalid start byte

This is the code:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

#importing dataset

dataset = pd.read_csv('food.csv')

The same thing works when i try the following-

import csv
rows = []

with open('ABBREV.csv', 'r') as f:
    csvreader = csv.reader(f)
    for row in csvreader:
        rows.append(row)
1

1 Answers

3
votes

Check the encoding of the file:

with open('food.csv') as f:
    print(f)

Then use that encoding for opening the CSV

dataset = pd.read_csv('food.csv', encoding = ???)

Pandas read_csv docs