Nov 14: Nested Data

Learning Objectives

After today's class, you should be able to:

  • Understand how lists and dictionaries can represent data
  • Explain different nested structures
  • Understand the main structures of the project
  • Use of csv and json files

Announcement

  • Programming Assignment 2 PA 2
    • Part C of PA 2 due Wednesday Nov 15th at 11pm

Today's class

Nested Data

Finish and review Inclass Activity

Mini lecture

Datasets

  • CORGIS
    • Collection of Really Great, Interesting, Situated Datasets
  • Example: County Demographics

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)  # dictionary

for item in data:
    if item["County"] == "Harrisonburg city":
        pprint(item)

Scavengar Hunt with Airline Data

Download Airlines CVS File and Airlines JSON File to answer these questions:

  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?

Your To-Do List

Due Wednesday November 15th at 11pm

Prepare for Quiz 5B on Thursday * Review on reading from files: what is returned? * File I/O and Sequences

PA 3 will be released soon