Skip to content

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
  • 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
  • List comprehensions!
    • Ex: [x ** 2 for x in range(10)]

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

  1. How many unique airport codes are in the data?
  2. What are the unique names of all the carriers?
  3. Which airport had the most flights in Dec 2015?
  4. Which had the most security delays in one month?

Tate (Art) Data

Download: Art CSV File and Art JSON File

  1. What is the oldest work of art in the collection?
  2. On average, how many words in are a work's title?
  3. Which artist has the most works of art in the data?
  4. How many unique artists in the data are still alive?

(Thanks to Dr. Mayfield for developing this activity.)