When doing data processing in Python, the following error is reported:
pandas.errors.ParserError: Error tokenizing data. C error: Expected 3 fields in line 28, saw 4
The reason for the error
First, let’s take a look at error reporting:
pandas.errors.ParserError: Error tokenizing data. C error: Expected 3 fields in line 28, saw 4
Translation:
Alphaers. errors.parserror: Error marking data. C Error: Three fields are required on line 28, see 4
The error was caused by a data set format error.
The solution
We need to modify the data format or make some Settings in the read-in. The following two methods are feasible:
1. Modify the read-in code
Add the following parameters after reading the code:
error_bad_lines=False #Addition of parameters
2. Modify the file format
I made the error because I was lazy and modified the suffix name directly. The correct way to do this is to open the file in the format required by another existing dataset. For example, I need a CSV file, and the existing file is XLSX. I need to open another CSV file, and the suffix name cannot be directly modified.