11/13¶
Announcements¶
- Project 2
- Part C Due Tuesday, Nov. 14
words_main.py
,words_utils.py
,words_game_utils.py
- Do not submit
words_file_utils.py
or any test code
Quiz 5a Debrief¶
- Filename vs File object
- Calling
open()
function - Using a
with
statement
- Calling
- Basic file I/O methods
- Reading lines from a file
- Writing lines to a file
Working with Structured Data¶
- CORGIS
- Collection of Really Great, Interesting, Situated Datasets
- Example: County Demographics
- CSV format (nested lists)
- JSON format (nested dictionaries)
- List comprehensions!
- Ex:
[x ** 2 for x in range(10)]
- Ex:
CSV example:
import csv
from pprint import pprint
data = []
with open("county_demographics.csv") as file:
reader = csv.reader(file)
data = [row for row in reader]
pprint(data[0])
JSON example:
import json
from pprint import pprint
with open("county_demographics.json") as file:
data = json.load(file)
for item in data:
if item["County"] == "Harrisonburg city":
pprint(item)
Scavenger Hunt¶
- Write code to answer each of the questions below
- Round 1: Using the CSV file
- Round 1: Using the JSON file
- The data is from the CORGIS project
Airlines Data¶
Download: Airlines CSV File and Airlines JSON File
- How many unique airport codes are in the data?
- What are the unique names of all the carriers?
- Which airport had the most flights in Dec 2015?
- Which had the most security delays in one month?
Tate (Art) Data¶
Download: Art CSV File and Art JSON File
- What is the oldest work of art in the collection?
- On average, how many words in are a work's title?
- Which artist has the most works of art in the data?
- How many unique artists in the data are still alive?
(Thanks to Dr. Mayfield for developing this activity.)