On this page:
1 Introduction
2 Exercise:   Providence Trees
2.1 Format
2.2 Questions
3 Exercise:   Ice Cream
3.1 Format
3.2 Questions
4 Helpful Hints
5 Code Templates
6 Handing In

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—you can even do this to print out full table! We expect you to submit the code you use to generate your answers as well as the answers themselves.

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
  1. What is the largest diameter of a tree in Providence?

  2. What is the address of said largest tree?

  3. 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
  1. What were the temperatures for the five time periods with the lowest ice cream consumption?

  2. 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.

  3. 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

Implementation code

6 Handing In

Captain Teach

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.