How can read two field of a csv file separately in python?
Question: I want to read two column of a csv file separately, but when I wrote code like
below python just show first column and nothing for second, but in the csv
file the second column also has lots of rows.

    
    
    import csv
    import pprint
    
    f = open("arachnid.csv", 'r')
    read = csv.DictReader(f)
    for i in range(3):
        read.next()
    
    for i in read:
        pprint.pprint(i["binomialAuthority_label"])
    
    for i in read:
        pprint.pprint(i["rdf-schema#label"])
    


Answer: The reason for this is that when you use DictReader the way you are using it
it will create what is called an iterator/generator. So, when you have
iterated over it once, you _cannot_ iterate over it again the way you are
doing it.

If you want to keep your logic as is, you can actually call seek(0) on your
file reader object to reset its position as such:

    
    
    f.seek(0)
    

The next time you iterate over your dictreader object, it will give you what
you are looking for. So the part of your code of interest would be this:

    
    
    for i in read:
        pprint.pprint(i["binomialAuthority_label"])
    
    # This is where you set your seek(0) before the second loop
    f.seek(0)
    
    for i in read:
        pprint.pprint(i['rdf-schema#label'])
    

