Daily analysis of data sources into Python, sometimes there will be errors and display garbled code problems, today to review the common errors.
Python code
import pandas as pd
import numpy as np
Df = pd read_csv invest_record_2018. CSV (” “)
Error message
UnicodeDecodeError Traceback (most recent call last)
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._convert_tokens
(pandas/_libs/parsers.c:14858)()
pandas/_libs/parsers.pyx in
pandas._libs.parsers.TextReader._convert_with_dtype
(pandas/_libs/parsers.c:17119)()
Error message shows the file encoding error, so adjust the code
import pandas as pd
import numpy as np
df=pd.read_csv(“invest_record_2018.csv”,encoding=”utf-8″)
Error report still, change the code
import pandas as pd
import numpy as np
df=pd.read_csv(“invest_record_2018.csv”,encoding=”gbk”)
Encoding =” iso-8859-1 “can also be used to stop the error
import pandas as pd
import numpy as np
df=pd.read_csv(“invest_record_2018.csv”,encoding=”ISO-8859-1″)
Neither code will display an error. You can continue writing.
Chinese garbled code problem
df.head()
Preview the first 5 lines, Chinese display garbled code
Continue to change the code
import pandas as pd
import numpy as np
df=pd.read_csv(“invest_record_2018.csv”,encoding=”gbk”)
df.head()
After execution, display is normal, problem solved.
Coding classification
Encoding =” UTF-8 “(encoding=” UTF-8″, encoding=” UTF-8 “, encoding=” UTF-8 “)
Python code
import pandas as pd
import numpy as np
Df = pd read_csv invest_record_2018. CSV (” “)
Error message
UnicodeDecodeError Traceback (most recent call last)
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._convert_tokens
(pandas/_libs/parsers.c:14858)()
pandas/_libs/parsers.pyx in
pandas._libs.parsers.TextReader._convert_with_dtype
(pandas/_libs/parsers.c:17119)()
Error message shows the file encoding error, so adjust the code
import pandas as pd
import numpy as np
df=pd.read_csv(“invest_record_2018.csv”,encoding=”utf-8″)
Error report still, change the code
import pandas as pd
import numpy as np
df=pd.read_csv(“invest_record_2018.csv”,encoding=”gbk”)
Encoding =” iso-8859-1 “can also be used to stop the error
import pandas as pd
import numpy as np
df=pd.read_csv(“invest_record_2018.csv”,encoding=”ISO-8859-1″)
Neither code will display an error. You can continue writing.
Chinese garbled code problem
df.head()
Preview the first 5 lines, Chinese display garbled code
Continue to change the code
import pandas as pd
import numpy as np
df=pd.read_csv(“invest_record_2018.csv”,encoding=”gbk”)
df.head()
After execution, display is normal, problem solved.
Coding classification
Encoding =” UTF-8 “(encoding=” UTF-8″, encoding=” UTF-8 “, encoding=” UTF-8 “)
Read More:
- How to Fix Parser rerror: error tokenizing data. C error: expected 2 fields in line 53, saw 3
- Solution of Unicode decodeerror -‘utf-8 ‘codec can’t decode byte 0xc4 in position 0 – invalid continuation byte
- Solution to garbled code problem after importing project in eclipse
- How to import Python from relative path
- Pandas memory error
- Solution of Chinese display garbled code in Git Bash
- Unable to call numpy in pychar, module notfounderror: no module named ‘numpy’
- (20200915 solved) vscope appears unable to open ‘hashable’_ class_ helper.pxi ‘
- Python error: importerror: DLL load failed: unable to find the specified module solution
- Python_ Part 2 programming problems (3)_ solve numpy.core.multiarray Failed to import problem
- Importing the multiarray numpy extension module failed
- Error report and solution of import panda in Windows 10
- The use of Chinese characters in Qt and the solution to the “error C2001: newline in constant” problem
- Reading and saving opencv Python video
- fatal error: Python.h: No such file or directory
- Python reports oserror: initializing from file failed
- Solve Python error Unicode error ‘UTF-8’
- fix yahoo finance
- Solution to the problem of Chinese garbled in gradle console in idea