-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
QST: Inconsistent behaviour in checking number of fields per row while read_csv() #41754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
To me this behaviour is quite consistent with what I would expect a CSV import to do. Having a value outside of the defined columns just doesn't make any sense, so the For example, if the contents of your CSV file were from some input, where you have to enter three fields, but the CSV contains a row with four columns, this means you have a bigger problem. If you have a row with only two columns and one In any way, checking for empty values after importing is always a good step, using - in your third example - |
This is a duplicate, please search the issue tracker, |
It is impolite to assume that each user opening an issue is stupid and lazy. But it is also impolite to point to other Issues without giving the links. If you want contributers to pandas you should work on your attitude. And as a "pandas member" you should know how to use GitHubs Issue tracker. Anything else is waste of ressources. |
@Codeberg-AsGithubAlternative-buhtz we have 3500 issue and very limited reviewers / volunteers. Please help us out here. |
Hi @Codeberg-AsGithubAlternative-buhtz, |
Thanks for the Issues and PR. I will monitor them. For 3: Yes the (IMHO inconsistent) behavior is described in docs. But it does not make it right. There should be no difference between the handling of to few and to many columns. But it is just my opinion. |
Given the sheer volume and quality of (voluntary!) work produced (see https://github.com/pandas-dev/pandas/commits?author=phofl for a start, and that's excluding reviews + issue triage), is demanding that they search the issue tracker for you really the best use of their resources?
Such comments are unwelcome - you've been warned |
I post this as a "Question" because I am quite new to
pandas
. So maybe I miss some understandings and the "problem" described by me is by design and you have good reasons for that.I use pandas 1.2.4, with Python 3.9.4 on Windows 10 64 bit.
As a user I would expect that pandas check the number of fields per row when importing via csv file. But IMHO it does not in all cases.
Example 1
Here is a csv file without header and but a set
names=
attribute with three fields. So pandas should be able to know how many fields/columns should be in the CSV file. The second row contains 4 instead of 3 fields.Pandas import this without warnrings or errors. The 4th field in the 2nd row is simply ignored.
Example 2
I added a header line into the csv file with again three fields.
So pandas should be able to know how many fields/columns should be in the CSV file.
And again the second row contains 4 instead of 3 fields.
Here an error occurs as I expect.
pandas.errors.ParserError: Error tokenizing data. C error: Expected 3 fields in line 3, saw 4
Example 3
There are less then 3 fields in the 2nd row. Again here is no warning or error. The missing field is set with
NaN
. And here it does not matter if you give the number of (expected) fields via header line in the CSV or vianames=
attribute.Want I want is to import CSV files and be informed if there are to many or less then the expected number of fields in any row.
The text was updated successfully, but these errors were encountered: