Sunday 15 February 2015

search - Loading Specific Data from a CSV file python -


I am working with CSV files that contain many data Each row contains data in the format shown below

name, age, gender, birth year

Mark, 18, M, 1978

Mary, 18, M, 1980

Marcus, 18, M, 1978

This data has been duplicated and so far there are 200 lines for the epics. What I want to know is that this is a way that I Open it and read it I can print only the 1978 lines. I, E will print only Mark and Marcus lines for the above data.

This is my code so far. How can I edit it to achieve my goal Is it possible? line = f.readlines () f = open ("names.csv", 'ru') for lines: [xx for x lines if ' 1978 'print x]

  with open ("name. CSV ") as FH: '1978' in line: print line   

Note that there is a standard library module for dealing with CSV files, but for your purpose None of that is needed; The above code snippet should be done. However, if your needs become more complicated then you can make CSV your side by reading instead of plain text as a CD.

No comments:

Post a Comment