Class 15 — Monday, September 30
String and CSV Chrestomathics
CVS Drugstore — Is not to be examined — CSV files yes
Look both ways
Agenda
- Chresthomatics
- CSV processing
Peer mentoring
- Some course personnel have volunteered to pilot an effort to provide peer mentoring support for CS 1112. If you are interested in participating, please fill out thi application.
Aesthetics
- Ongoing criteria
Downloads
- Module url.py
- Program weathering_heights.py
- Program get_a_dataset.py
- Program csv_is_not_a_pharmacy.py
To do
- Review artifacts
- Check out homework solutions.
- Also check out Spring 2019 Test 1 program solutions.
Some datasets
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 and the Philosopher's Stone, 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
Location, Author, Max Height, Min Height
Narnia, Lewis, 4810, -10
Neverland, Milne, 426, -2
Oz, Baum, 1231, 679
Sleepy Hollow, Irving, 1629, 304
Stars Hollow, Sherman-Palladino, 725, 152
Toyland, MacDonough, 6187, 0
Wonderland, Carroll, 5895, -5
Country, Females, Males
Australia, 11175724, 11092660
Fiji, 421365, 439258
French Polynesia, 132082, 138682
New Caledonia, 125322, 125548
New Zealand, 2223281, 2144855
Papua New Guinea, 3359979, 3498287
Solomon Islands, 259909, 278239
Vanuatu, 117573, 122078
Asta,Hachiko,Laika,Lassie
59.0,TruE
faLse,3.14,271
01,10,10.0,ABC
Zipcode, Town, State, Latitude, Longitude
00210, Portsmouth, NH, 43.005895, -71.013202
00211, Portsmouth, NH, 43.005895, -71.013202
00212, Portsmouth, NH, 43.005895, -71.013202
00213, Portsmouth, NH, 43.005895, -71.013202
00214, Portsmouth, NH, 43.005895, -71.013202
00215, Portsmouth, NH, 43.005895, -71.013202
00501, Holtsville, NY, 40.922326, -72.637078
00544, Holtsville, NY, 40.922326, -72.637078
...
99403, Clarkston, WA, 46.400365, -117.08313
99536, Kennewick, WA, 46.216706, -119.160173
You don't need a weather man to know which way the wind blows
<!DOCTYPE html> <html class="no-js"> ...
<div class="row row-odd row-forecast"><div class="col-sm-2 forecast-label"><b>Today</b></div> <div class="col-sm-10 forecast-text">
Scattered showers and thunderstorms. Mostly cloudy, with a high near 80. East wind around 5 mph. Chance of precipitation is 50%.
</div> ...
</body> </html>
-
Program weathering_heights.py
- Makes use of module url.py to access a weather forecast for a user-specified zipcode by querying the forecast.weather.gov website
Some program runs
Enter zipcode: 22903
Scattered showers and thunderstorms. Mostly cloudy, with a high near 80. East wind around 5 mph. Chance of precipitation is 50%.
Enter zipcode: 10036
Mostly cloudy, with a high near 67. Southeast wind around 10 mph.
Enter zipcode: 83278
Scattered snow showers after noon. Mostly sunny, with a high near 40. Calm wind. Chance of precipitation is 40%. Little or no snow accumulation expected.
Algorithm
- Get access to url get web content capabilities
- Define helpful constants — base query, forecast delimiters, lengths of forecast delimiteres
- Get user zip code of interest
- Create the query link to get forecast from national weather service
- Get the contents of the page found at the forecast link
- Find indexes of query front and rear delimiters
- Find indexes of forecast front and rear
- Get the forecast substring from the page
- Print the forecast
Getting a dataset step by step
-
Program get_a_dataset.py
- Get a user-specified web csv resource as a Python dataset
Some program runs
Enter name of dataset: best-sellers.csv
header:
['Name', 'Author', 'Language', 'Date', 'Sales']
data:
[['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 and the Philosopher's Stone", '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']]
Enter name of dataset: elevations.csv
header:
['Location', 'Author', 'Max Height', 'Min Height'],
data:
[['Narnia', 'Lewis', 4810, -10], ['Neverland', 'Milne', 426, -2], ['Oz', 'Baum', 1231, 679], ['Sleepy Hollow', 'Irving', 1629, 304], ['Stars Hollow', 'Sherman-Palladino', 725, 152], ['Toyland', 'MacDonough', 6187, 0], ['Wonderland', 'Carroll', 5895, -5]]
Streamling a dataset
-
Program csv_is_not_a_pharmacy.py
- Makes use of module url.py to access a dataset.
Some program runs
Enter name of dataset: oceania.csv
['Country', 'Females', 'Males']
['Australia', '11175724', '11092660']
['Fiji', '421365', '439258']
['French Polynesia', '132082', '138682']
['New Caledonia', '125322', '125548']
['New Zealand', '2223281', '2144855']
['Papua New Guinea', '3359979', '3498287']
['Solomon Islands', '259909', '278239']
['Vanuatu', '117573', '122078']
['Country', 'Females', 'Males']
['Australia', 11175724, 11092660]
['Fiji', 421365, 439258]
['French Polynesia', 132082, 138682]
['New Caledonia', 125322, 125548]
['New Zealand', 2223281, 2144855]
['Papua New Guinea', 3359979, 3498287]
['Solomon Islands', 259909, 278239]
['Vanuatu', 117573, 122078]
Enter name of dataset: rows_of_stuff.csv
['Asta', 'Hachiko', 'Laika', 'Lassie']
['59.0', 'TruE']
['faLse', '3.14', '271']
['01', '10', '10.0', 'ABC']
['Asta', 'Hachiko', 'Laika', 'Lassie']
[59.0, True]
[False, 3.14, 271]
[1, 10, 10.0, 'ABC']
Where is it
-
Program where_is_it.py
- Determines a rough estimate of the center of continental USA by making use of CSV dataset continental-usa.csv.
- Question
- How should we determine the estimate?
Lebanon, KS, 66952, 39°48′38″N 98°33′22″W
© 2019 Jim Cohoon | Resources from previous semesters are available. |