Class 12 – Monday, February 10
A dataset by any other name is still a dataset (but it is not a set)
In a loop, a loop — Nesting, but not like a bird — Repeating again
Look both ways
Agenda
- Extend
print()
function functionality
- Introduce datasets
For the fun of it
- Reveal one of your super power(s).
- Share a selfie.
- Sign up for peer mentoring
To do list
- Review class artifacts.
- Complete homework.
- Prepare for Test 1 (Class 17 — Friday, 2/21/2020)
Downloads
- Program dataset_intro.py
- Program lotta_books.py
Datasets
- A dataset is a list whose elements are lists.
- Datasets are sometimes called tables or data sheets
- The elements of a two-dimensional dataset are called rows. The elements of a row are called data values or cells.
- Most of the datasets that we process will come from the web.
- The datasets acquired by programs are often CSV files; that is, the values are separated by commas.
- One CSV dataset we will consider is the best selling fictional books of all time
Program dataset_intro.py
- Demonstrates looping through a dataset in different ways
Program run
table: [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L', 'M']]
the table has 4 rows
row ['A', 'B', 'C'] has 3 columns
row ['D', 'E', 'F'] has 3 columns
row ['G', 'H', 'I'] has 3 columns
row ['J', 'K', 'L', 'M'] has 4 columns
row 0 : ['A', 'B', 'C']
row 1 : ['D', 'E', 'F']
row 2 : ['G', 'H', 'I']
row 3 : ['J', 'K', 'L', 'M']
row 0 : ['A', 'B', 'C']
column 0 of row 0 : A
column 1 of row 0 : B
column 2 of row 0 : C
row 1 : ['D', 'E', 'F']
column 0 of row 1 : D
column 1 of row 1 : E
column 2 of row 1 : F
row 2 : ['G', 'H', 'I']
column 0 of row 2 : G
column 1 of row 2 : H
column 2 of row 2 : I
row 3 : ['J', 'K', 'L', 'M']
column 0 of row 3 : J
column 1 of row 3 : K
column 2 of row 3 : L
column 3 of row 3 : M
A B C
D E F
G H I
J K L M
Program lotta_books.py
- Examines a literal dataset that I have into the program from the web dataset best_sellers.csv
Program run
['Name', 'Author', 'Language', 'Date', 'Sales']
['Don Quixote', 'de Cervantes', 'Spanish', 1605, 500000000]
['A Tale of Two Cities', 'Dickens', 'English', 1859, 200000000]
['The Lord of the Rings', 'Tolkien', 'English', 1954, 150000000]
['The Little Prince', 'de Saint-Exupery', 'French', 1943, 140000000]
['Harry Potter', 'Rowling', 'English', 1997, 120000000]
['The Hobbit', 'Tolkien', 'English', 1937, 100000000]
['And Then There Were None', 'Christie', 'English', 1939, 100000000]
['Dream of the Red Chamber', 'Xueqin', 'Chinese', 1754, 100000000]
["Alice's Adventures in Wonderland", 'Carroll', 'English', 1865, 100000000]
sales column: 4
Total sold: 1.51 billion
© 2020 Jim Cohoon | Resources from previous semesters are available. |