The code is as follows:
f = csv.reader(open(csvroot, 'r',encoding='utf-8'))
for i in f:
print(i)
Solution: view the file encoding format
import chardet
f = open(full_csvroot, 'rb')
data = f.read()
print(chardet.detect(data))
# Outcome:
# {'encoding': 'GB2312', 'confidence': 0.99, 'language': 'Chinese'}
Amend to read:
f = csv.reader(open(csvroot, 'r',encoding='GB2312'))
for i in f:
print(i)
Perfect operation
Read More:
- Django CSV file Error: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb5 in position 0: invalid start
- 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] git review Error: UnicodeDecodeError: ‘gbk‘ codec can‘t decode
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 10-11: malformed
- 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] ParserError: NULL byte detected. This byte cannot be processed in Python‘s native csv library
- [Solved] Grid Search Error (GridSearchCV): ‘ascii‘ codec can‘t encode characters in position 18-20: ordinal not in r
- Python: How to get the size of the picture (byte/kb/mb)
- [Solved] RuntimeError: function ALSQPlusBackward returned a gradient different than None at position 3, but t
- can‘t multiply sequence by non-int of type ‘numpy.float64‘
- How to Solve word2vec Module Error: AttributeError & UnicodeDecodeError
- [Solved] YOLO v5 Error: AttributeError: Can‘t get attribute SPPF on module models
- [Solved] Can‘t pickle local object ‘_createenviron.<locals>.encodekey‘
- AttributeError: can‘t set attribute [How to Solve]
- [Solved] Pytorch Tensor to numpy error: RuntimeError: Can‘t call numpy() on Tensor that requires grad.报错