Skip to content

CSV file on Python #21498

Answered by fire-eggs
Charlineprg asked this question in General
Discussion options

You must be logged in to vote

You want to read about using csv.DictReader instead of csv.reader.

With DictReader you will get a dictionary which is indexed based on the column names in the first line of the file. Then you will be able to do things like:

if prenom['sexe'] == '1':

You can’t do that with the regular csv.reader.

Your “csv” file is actually using a semi-colon as the delimiter. It may be necessary to let the csv package know this, by including 

delimiter=';'

as a parameter to the csv.DictReader call.

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants