Students learn how to extract individual rows from a table, and columns from a row.

Lesson Goals

Students will be able to…​

  • Given a human-language request for a data display involving the entire Animals Dataset, break it down into parts and generate the display.

  • Given a Table, use the row-n method to extract any Row from that table

  • Given a Row, use the column lookups to extract the value of any column in the Row

Student-facing Lesson Goals

  • Let’s practice making data displays to answer our questions about the data and retrieving information from tables.



data row

a structured piece of data in a dataset that typically reports all the information gathered about a given individual


a function that is only associated with an instance of a data type, which consumes inputs and produces an output based on that instance

🔗Row Lookups 30 minutes


Students learn how to define values in Pyret, and practice by defining Numbers, Strings, and Images. They also learn how to define an individual row from a table in Pyret.


Sometimes we have a value that we want to use again and again, and it makes sense to define a name for it. Every definition includes a name and a value. In the code below, we have definitions for a String, a Number and an Image.

name = "Flannery"
age = 16
logo = star(50, "solid", "red")
  • What are the names given in each of these?

    • name, age, and logo

  • What are the values?

    • the String "Flannery", the Number 16, and an Image of a solid red star


Remind students that examples of lookup questions include, “How many legs does Felix have?” or "What species is Sheba?"

  • How many rows do we need to answer a Lookup question?

    • Just one! Lookups can be answered just by finding the right row!

Make sure sure students understand we only need one row!

Ask Questions icon🖼Show image What code can we write, to let us define a single row? Tables have special functions associated with them, called Methods, which allow us to do all sorts of things with those tables. For example, we can get the first data row in a table by using the .row-n method: animals-table.row-n(0)

Don’t forget: data rows start at index zero!

  • Open your saved Animals Starter File (or make a new Animals Starter File copy), and click “Run”.

  • In the Interactions Area, use the .row-n method to get the second and third data rows.

  • Find .row-n in your Contracts page. What is the Domain of .row-n? What is the Range?

    • Its domain is Number. Its range is Row.

A table method is a special kind of function which always operates on a specific table. A.row-n(0) and B.row-n(0) will return different rows, if A and B are different tables.

How would you get the second row out of the animals table? The third?

The code below will define the first row from the animals table:

sasha = animals-table.row-n(0)

It’s often better to name our Row definitions according to the property we care about. In this case, the fact that this row is a cat is much more interesting than the fact that her name is Sasha:

cat-row = animals-table.row-n(0)

  • In the Animals Dataset, there are subsets that we might want to analyze: dogs, cats, lizards, old animals, young ones, etc.

  • Complete Defining Rows.

  • When you’re done, open your saved Animals Starter File (or make a new Animals Starter File copy) and add these definitions after the definitions for dog-row and cat-row.

  • The rows you added will be used later!


  • We named rows by a lot of different properties (e.g. - their species, sex, etc). What are some other properties of rows in this dataset that we could use?

  • What are some properties of your dataset that you might want to define rows for?

🔗Column Lookups 25 minutes


Students learn how to access a particular column from a row.


We can also access columns of a Row, by using a Row Accessor. Row accessors start with a Row value, followed by square brackets, and the name of the column where the value can be found. Here are three examples that use row accessors to get at different columns from the first row in the animals-table:


And of course, we can use our defined name, substituting it in place of all the redundant code:




  • Why is it important to be able to define individual rows?

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting