Read CSV file

Read CSV file

Sachin R Tendulkar made his ODI debut in 1989. OneDayInternational.csv is a CSV file containing about 200 records on Sachin’s ODIs from 1990 to 1998.  Read this CSV file using DictReader() and display the contents in the first 10 rows.

Here is the sample of first 2 records from OneDayInternational.csv

Country Player Runs ScoreRate MatchDate Ground Versus URL
Ind Sachin R Tendulkar 0 0  1/3/1990     Carisbrook      NZ         673
Ind    Sachin R Tendulkar   36  92.30769231 6/3/1990  Basin Reserve NZ   676

Code :-

import csv
file='OneDayInternational.csv'
reader=csv.DictReader(open(file,'r'))
for i,l in enumerate(reader):
    print(l)
    if(i>=9):
        break

Leave a Comment

Your email address will not be published. Required fields are marked *