[Tutor] Reading a CSV file
John Weller
john at johnweller.co.uk
Fri Jun 12 13:59:16 EDT 2020
I have a CSV file with 366 rows each with 4 comma separated fields; day_no,
date, sunrise, sunset. The top row contains the field names. I want access
the time of sunrise and sunset from file for a particular day_no.
I have tried:
import csv
with open('sun_times_gmt.csv', newline= '') as csvfile:
sun_times = csv.DictReader(csvfile, delimiter=',')
for row in sun_times:
print(row['sunrise'])
but it prints out the entire column. How do I specify a particular row?
TIA
John Weller
01380 723235
07976 393631
More information about the Tutor
mailing list