Tables 1
1 Introduction
You’ve seen tables of data for years. In computer science, these are especially important. Sometimes known as relational databases, they are one of the primary ways of storing data on the Web, and power most of the systems you use.
In Pyret, we’ve made it easy to get started with tables. First, you don’t need to learn how to use a full-fledged “database manager”, because Pyret lets you store your tables in a Google Spreadsheet. Second, Pyret provides special commands for quickly processing tabular data. See the documentation for more information, as well as this textbook chapter.
For this assignment, you should write code that assigns your answers
to the identifiers in the provided template files. Once you run your
program, you can type the identifiers in the interactions area to view
the results—
2 Exercise: Providence Trees
This semester you will hear plenty about trees, especially with the beautiful New England fall foliage. To prepare for fall, let’s learn about the trees in Providence. The city has taken inventory of over 24,000 trees and provided the information to you.The data are from the City of Providence. To make your life a bit easier, we’ve cut this down (haha) to 2,000 entries. You will answer some questions about them.
2.1 Format
The data are in a table with the following columns and their types:
address |
| street |
| side |
| species |
| diameter |
String |
| String |
| String |
| String |
| Number |
2.2 Questions
What is the largest diameter of a tree in Providence?
What is the address of said largest tree?
What is the diameter of the tree at “165 PROSPECT ST”? (Use string-contains to help with this.)
3 Exercise: Ice Cream
We will now use a dataset of ice cream measurements made between 1951 and 1953 (which would explain the prices!).Hildreth, C. and J. Lu (1960) Demand relations with autocorrelated disturbances, Technical Bulletin No 2765, Michigan State University. The data measure average ice cream consumption (in pints), average weekly family income (in US dollars), the price of ice cream (per pint), and the temperature (in degrees fahrenheit) every four weeks for a little over two years.
3.1 Format
The data are in a table with the following columns and their types:
time-period |
| amt-consumed |
| income |
| price |
| temperature |
Number |
| Number |
| Number |
| Number |
| Number |
3.2 Questions
What were the temperatures for the five time periods with the lowest ice cream consumption?
Extend the table with the column amt-spent indicating the amount spent on ice cream, which would be the average amount consumed times the average cost.
What is the time period when the most money was spent on ice cream?
4 Helpful Hints
The code template given below already contains commands to import the tree and ice-cream data, under the names trees and ice-cream, respectively.
The main table operations consume and produce tables. Though you can also extract data from a table if you wish, this depends on types (like lists) that you haven’t yet been taught. Therefore, you do not need to extract data from the table; just transform each table into a form where the answer can be readily observed (e.g., as the top, bottom, or sole row of a table).
If you have questions about tables, Pyret, or cs019, please come to TA hours this week! No question is too simple!
5 Code Templates
6 Handing In
Please include a text file containing your answers to the six questions, as well as a copy of the code you used to help you get the answers, submitted in two separate steps on Captain Teach.