close

[Solved] pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12

Hello Guys, How are you all? Hope You all Are Fine. Today I’m trying to use pandas to manipulate a .csv file but I get this error: pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12 in Python. So Here I am Explain to you all the possible solutions here.

Without Wasting your time, Lets start This Article to Solve This Error.

How This pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12 Error Occurs ?

Today I’m trying to use pandas to manipulate a .csv file but I get this error:

pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12

My Code is pretty simple.

data = pd.read_csv(path)

How To Solve pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12 Error ?

Question: How To Solve pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12 Error?
Answer: To Solve pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12. Just disable error_bad_lines. Do note that this will cause the offending lines to be skipped. you can try my code.

Solution 1

Just disable error_bad_lines. Do note that this will cause the offending lines to be skipped. you can try my code:

data = pd.read_csv(yourfileName', error_bad_lines=False)

Solution 2

To solve it, try specifying the sep and/or header arguments when calling read_csv. For instance,

df = pandas.read_csv(yourfileName, sep='delimiter', header=None)

Solution 3

This should be an issue of delimiter, as most of the csv CSV are got create using sep='/t' so try to read_csv using the tab character (\t) using separator /t. so, try to open using following code line.

data=pd.read_csv("File_path", sep='\t')

Solution 4

I have specified the column names in a list beforehand and then pass them into names, and it solved it immediately.

col_names = ["name", "email", "number", ...]
df = pd.read_csv(yourfileName, names=col_names)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment