How to Solve Python Pandas Read or Import Files Error

1. File not found

Error: [Errno 2] No such file or directory: 'C:\\Users\\ssw0926\\Desktop.chengji.csv'

1. Wrong file path

Methods to avoid errors: do not manually enter the file address, select copy.

Select the file to be read, press shift and right mouse button, and copy file address will appear.

2. Remember to add the escape character R

For example:

df=pd.read_csv(r”C:\Users\ssw0926\Desktop\chengji.csv”,encoding=”utf-8″)

2. When the file contains Chinese, it is easy to have character coding problems.

1. Error message:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte

Solution: try to transform encoding. For example, change encoding = “UTF-8” to encoding = “GB2312” or other codes.

Read More: