The CSV File Format and Two Dimensional Lists¶

CS 65: Introduction to Computer Science I¶

A useful string method: split()¶

split() is a string method that will break a string into parts based on some delimeter

In [1]:
marathon_time = "4:52:20"
marathon_time_split = marathon_time.split(":")
print(marathon_time_split)
['4', '52', '20']
In [2]:
rainfall_data = "0.0, 0.4, 1.3, 1.1, 2.5, 0.0, 0.6"
rainfall_list = rainfall_data.split(", ")
print(rainfall_list)
print(float(rainfall_list[4]))
['0.0', '0.4', '1.3', '1.1', '2.5', '0.0', '0.6']
2.5

CSV files - comma separated values¶

CSV files is a common, simple file format for data stored in tables. They can often be opened with either spreadsheet software or text editors.

National parks data is from https://en.wikipedia.org/wiki/List_of_areas_in_the_United_States_National_Park_System