0

I want to import my csv dataset using pandas but i keep having this error code

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 2961: invalid start byte

I tried importing using excel file format but it incorrectly displays the date column...

The_Data_Guy
  • 123
  • 1
  • 4
  • 1
    Please do not blindly apply a fix for this. It is vital to understand how text works in modern programs / on modern computers; in particular, what an *encoding* is. The problem is easy to fix if you know the intended encoding of the source data, but simply examining the data can only ever let you *guess* at what was intended. Please read https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ for a background and https://nedbatchelder.com/text/unipain.html for Python-specific advice. – Karl Knechtel May 26 '22 at 22:55

2 Answers2

0

its simple. Import the csv file and add (encoding='cp1252') behind the import command Here it is:

df = pd.read_csv("file or file path", encoding='cp1252')

Thats it. It imports the dataset all fine and good.

The_Data_Guy
  • 123
  • 1
  • 4
0

All you need to is add (encoding='cp1252') after the import command... It should look like this:

variable= pd.read_csv("file or file path", encoding='cp1252') Tell me if that dosent work!

Jogvi
  • 77
  • 1
  • 7