If you face an encoding error due to encoding on your file not being the default as mentioned by the pd.read_csv()
docs , you can find the encoding of the file by first installing chardet
followed by the below code:
import chardet
rawdata = open('D:\path\file.csv', 'rb').read()
result = chardet.detect(rawdata)
charenc = result['encoding']
print(charenc)
This will give you the encoding of the file.
Once you have the encoding, you can read as :
pd.read_csv('D:\path\file.csv',encoding = 'encoding you found')
or
pd.read_csv(r'D:pathfile.csv',encoding = 'encoding you found')
You will get the list of all encoding here
Hope you find this useful.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…