-2

I am writing a command to join files on macbook M1 using Jupyter notebook, but I have a problem when joining CVS files in the following command. I will post the full code:

import pandas as pd
import os 
files = [file for file in os.listdir("/Users/tadinhkhanh/Downloads/Training Python/Data Science/Tut Training Data Science (Youtube - Keith Galli) (Python + Numpy)/SalesAnalysis/Sales_Data")]
all_months_data = pd.DataFrame()
for file in files:
    df = pd.read_csv("/Users/tadinhkhanh/Downloads/Training Python/Data Science/Tut Training Data Science (Youtube - Keith Galli) (Python + Numpy)/SalesAnalysis/Sales_Data/"+file)
    all_months_data = pd.concat([all_months_data, df])
all_months_data.head()
halfer
  • 19,824
  • 17
  • 99
  • 186
  • UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte – Leonardo9991 Feb 01 '22 at 18:32
  • 4
    Does this answer your question? [UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 3131: invalid start byte](https://stackoverflow.com/questions/38518023/unicodedecodeerror-utf8-codec-cant-decode-byte-0x80-in-position-3131-invali) – BigBen Feb 01 '22 at 18:49
  • It's not working, sorry bro – Leonardo9991 Feb 01 '22 at 19:10

1 Answers1

-4

Me too got this error while running my python file when i upgrade to 3.9 , I go through some python documentations and its an feature added from 3.9 like mentioning the format of unicode which we are going to use in our code. So, it won't need to call every codec's.

Try adding this line at top of your python file,

# -*- coding: utf-8 -*-

If above one not works try adding these two line,

#!/usr/bin/python
# -*- coding: utf-8 -*-

Edited : To add more information and additional answer.

Philip Zx
  • 15
  • 7
  • Sorry, it's not working, i used Python 3.9 – Leonardo9991 Feb 01 '22 at 19:08
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 01 '22 at 20:59
  • edited and updated answer. kindly recheck. – Philip Zx Feb 02 '22 at 03:56
  • The encoding comment controls how Python reads your _program_ source, but the OP is asking about reading a data file _from_ that program. – tripleee May 13 '22 at 10:11