Skip to content
Learnearn.uk » Python Unit Home » Python CSV Files Tutorial

Python CSV Files Tutorial

CSV → 2D List

Reading a CSV File into a 2 Dimensional Python List

Sometimes you will need to read data stored in comma separated value (CSV) files. You can use the csv module in order to achieve this.

import csv

f = open('mycsvfile.csv','r')
reader = csv.reader(f, delimiter = ',')

items = []
for row in reader:
     items.append(row)

CSV files usually use a comma as the delimiter between each data item, but sometimes might use a tab or other character instead.

Tutorial Video

YouTube Blocked? Try the Google Drive Version

2D List → CSV

CSV → Dictionary

Dictionary → CSV

Challenge 37

38

39

40