Answers for "csv.DictReader Skip Lines"

0

csv.DictReader Skip Lines

with open("myfile.csv", encoding='utf8') as fIn:
	#skip the first 100 rows 
    for i in range(100):
		#fIn.next()  # use next for python2
        fIn.readline() # use readline for python3 
	
    #open file at row 100 
    fieldnames = ["first_name","last_name"]
    reader = csv.DictReader(fIn,fieldnames=fieldnames)
	
    #now loop through file at row 101
	for row in reader:
		print(row['name'])
Posted by: Guest on August-27-2021

Python Answers by Framework

Browse Popular Code Answers by Language