UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb5 in position 0: invalid start
This csv file I opened in jupyter using pd.read_csv open no problem
But after I cleaned the data and saved it as a new csv, I couldn’t open it and got an error
Solution: in the views.py direct cleaning work, the data will be stored in order into a list, using a loop to iterate through the database, the following is the code (less efficient after all is iterative. Welcome to share a better way)
df = pd.read_csv(r"xxxxx\xxx.csv", encoding='utf-8')
... # datas clean up
ls = []
for index, row in df.iterrows():
res = []
for i in df:
res.append(row[i])
ls.append(res)
for i in range(len(ls)):
try:
XXX.objects.create(title=ls[i][0], rating=ls[i][1])
except Exception as e:
print(e)
return HttpResponse('Datas save successfully')
Read More:
- [Solved] UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xbf in position 7: invalid start byte
- How to Solve Pytorch DataLoader Loading Error: UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe5 in position 1023
- [Exception]’ascii’ codec can’t decode byte 0xe8 in position 2: ordinal not in range(128)
- [Solved] SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xbe in position 0
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 10-11: malformed
- [Solved] git review Error: UnicodeDecodeError: ‘gbk‘ codec can‘t decode
- [Solved] ParserError: NULL byte detected. This byte cannot be processed in Python‘s native csv library
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 6-7: malformed
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- Python Error: SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3:
- [Solved] Grid Search Error (GridSearchCV): ‘ascii‘ codec can‘t encode characters in position 18-20: ordinal not in r
- [Solved] Ubuntu install virtualenv error: UnicodeDecodeError
- How to Solve jupyter notebook Read CSV files Error
- Pandas read_csv pandas.errors.ParserError: Error tokenizing data
- How to Solve word2vec Module Error: AttributeError & UnicodeDecodeError
- [Solved] Django Configurate celery error: django.db.utils.DatabaseError
- Python: Django exception when executing migrate operation: django.db.utils.OperationalError: (1051, “Unknown table’xxx’”)
- [Solved] Django Access to the backend error: Invalid block tag on line 98: ‘trans‘, expected ‘elif , ‘else‘或‘ endif. Did you forget
- [Solved] Django project locally Open Error: importerror: couldn’t import Django