0

Upon calling a csv file I am getting the following error

ParserError: Error tokenizing data. C error: Expected 1 fields in line 12, saw 2

I opened my csv file and then went to the line and saw that the error is coming because one of the numbers is with decimals but separated by a cooma.

That entire column of my csv file has whole numbers but also decimals numbers that look like the following .

385433,4

Not sure how I can resolve this error when reading the csv file using pandas

5
  • pd.read_csv(filename, decimal = ',') Commented Feb 25, 2020 at 15:58
  • @Sayandip Dutta, for some reason I am getting the same error Commented Feb 25, 2020 at 16:05
  • What does the rest of the data look like? Commented Feb 25, 2020 at 17:07
  • Show a few actual lines of the CSV file (change sensitive data if needed). Commented Feb 25, 2020 at 17:25
  • @Mark Tolonen, my lines are separated by ; and the if I remove that line the next error comes exactly at the other lines that has a decimal number seperated by a comma example 154,65 Commented Feb 26, 2020 at 9:05

1 Answer 1

2

It sounds like you have European-formatted CSV. Since you haven't provided a real sample of your CSV as requested, I will guess. If this doesn't solve your issue, edit your question to provide an actual sample:

Given test.csv:

c1;c2;c3
1,2;3,4;5,6
3,4;5,6;7,8

Then:

import pandas as pd
data = pd.read_csv('test.csv',decimal=',',delimiter=';')
print(data)

Produces:

    c1   c2   c3
0  1.2  3.4  5.6
1  3.4  5.6  7.8
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.