0

Seems like this has been addressed so many times, yet I'm not able to resolve it. Here's a minimal example of my CSV:

Issue, Content Test, "A, B" Test, "A, B, C" 

Here's the read_csv code (tried all sorts of combinations regarding parameters):

df = pd.read_csv('data.csv', delimiter=",", quotechar='"', encoding="utf-8") 

Here's the error: ParserError:

Error tokenizing data. C error: Expected 3 fields in line 3, saw 4

I created the CSV file with a plain text editor. Wondering also why the interpreter expects 3 fields..

3
  • change your syntax to : df = pd.read_csv('data.csv', delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL, encoding="utf-8") Commented Sep 5, 2023 at 8:35
  • thx, but didn't help.. Commented Sep 5, 2023 at 8:41
  • 3
    Your CSV is invalid, there shouldn't be a space between the delimiter and the quotes, use skipinitialspace=True Commented Sep 5, 2023 at 8:44

2 Answers 2

2

Try

df = pd.read_csv('data.csv', delimiter=",", quotechar='"', skipinitialspace = True, encoding="utf-8") 
Sign up to request clarification or add additional context in comments.

1 Comment

you might want to explain why, see my comment ;)
0

For what you need the delimiter in this case?

If you follow the post pandas read csv with extra commas in column , it should be:

 df = pd.read_csv('data.csv', quotechar="'", encoding="utf-8", sep=",") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.