(Also available in CODAP)
Students learn about Transformers, which allow them to order, filter, and build columns to extend the animals table.
Lesson Goals |
Students will be able to…
|
Student-facing Lesson Goals |
|
Materials |
|
Preparation |
|
🔗Sorting Tables, Part 1 15 minutes
Overview
Students sort a column on a table by actually changing the table.
Launch
Open the Animals Dataset in CODAP. How many animals' names start with the letter M? What would make it easier to figure out how many animals' names start with the letter M?
Investigate
Student work in groups or pairs. They will sort various columns on the table by clicking the attribute name, and selecting from the drop-down menu either Sort Ascending
or Sort Descending
.
-
Let’s sort the animals alphabetically by name and see if we get the same answer as we did before!
-
Sort the animals by age, from youngest to oldest.
-
Sort the animals from heaviest to lightest.
-
Sort the animals table by how long it took for each animal to be adopted, in ascending order.
Synthesize
-
Can you think of a situation when it would be useful to sort animals from heaviest to lightest?
-
Does sorting
animals-table
produce a new table, or change the existing one? How do you know? -
Can you think of a situation where CODAP’s default behavior - to alter the table each time we sort it - might inhibit more sophisticated data analysis?
🔗Sorting Tables, Part 2 10 minutes
Overview
Using the Sort
Transformer, students sort rows of a table in ascending or descending order, according to one column. When they use transformers, students are building and modifying a copy of the original table.
Launch
The Transformers plugin allows students to transform datasets to produce new, distinct datasets, rather than modifying the original input dataset itself.
First, show students how they can access the Transformers plugin (see screenshot on right), and invite them to explore the different Transformers available.
Explain to students that the Sort
Transformer consumes: (1) a dataset; (2) a formula; (3) the type that the formula evaluates to; and (4) a sort direction (ascending or descending). But what does it produce?
What’s a Contract?! Contracts help us keep track of the different Transformers we’ll be using, and how they operate on each Row of a table. Every contract has three imporant parts:
Check out the screenshot of the Transformers plugin below. What are the domain and range for The Transformer |
Investigate
-
Open the
Transformer
plugin, and choose the transformerSort
. Selectanimals-dataset
. In the formula expression box, typeName
. Selectascending
as the direction andApply Tranformer
. What happens? -
Next, see what happens when you select
descending
. -
Sort the animals table from heaviest to lightest.
-
Sort the animals table alphabetically by species.
-
Sort the animals table by how long it took for each animal to be adopted, in ascending order.
Common Misconceptions
Students may be more familiar with filters that actually change the table. In CODAP, all transformers produce a brand new table. Filtered tables are automatically saved; CODAP titles each new table with a number in curly braces at the end (for example, Filter(Animals-Dataset) {1}
) to indicate how many times the transformer has been applied. When students apply a transformer, they have the option of selecting the original table from the dropdown menu, or a new table that they’ve generated. Students can also rename saved tables, if they’d like.
Synthesize
-
Does the transformer
Sort
produce a new table, or change the existing one? -
You’ve now learned two different strategies for sorting a column of a table. What do the two strategies have in common? How are they different?
🔗Filtering Tables 20 minutes
Overview
Students learn how to filter tables by removing Rows.
Launch
Explain to students that you have "Function Cards", which describe the purpose statement of a function that consumes a Row from a table of students, and produces a Boolean (e.g. - "this student is wearing glasses"). Select a volunteer to be the "Filter Transformer", and have them randomly choose a function card from from the Function Cards set, and make sure they read it without showing it to anyone else.
Have 6-8 students line up in front of the classroom, and have the filter transformer go to each student and say "stay" or "sit" depending on whether their function would return true or false for that student. If they say "sit", the student sits down. If they say "stay", the student stays standing.
Ask the class: based on who sat and who stayed, what function was on the card?
The Filter
Transformer takes a dataset and produces a copy of it that contains only the cases for which the given formula evaluates to true.
Suppose we want to get a table of only animals that have been fixed? The Filter
transformer consumes a dataset to filter and a formula expression that evaluates to either true or false.
Investigate
-
Open the
Transformer
plugin, and choose the transformerFilter
. Selectanimals-dataset
. In the formula expression box, typeFixed = “TRUE”
. Apply the transformer. What happens? -
Does CODAP mind if you forget to capitalize? What about if you leave out quotation marks? Examine the error messages that appear if you are just a little careless as you enter text into the formula expression box.
-
This time, in the formula expression box, type
Age > 5
. What did you get? -
Now try
Species = “dog”
The Filter
Transformer walks through the table, applying whatever formula it was given to each row, and produces a new table containing all the rows for which the formula returned true
. Notice that Filter
takes a dataset and produces a copy of it that contains only the cases for which the given formula evaluates to true. If it consumes anything besides a single Row
, or if it produces anything else besides a Boolean
, we’ll get an error.
Synthesize
Debrief with students. Some guiding questions on filtering:
-
Suppose we wanted to determine whether cats or dogs get adopted faster. How might using the
Filter
transformer help? -
If the shelter is purchasing food for older cats, what filter would we write to determine how many cats to buy for?
-
Can you think of a situation where filtering fixed animals would be helpful?
🔗Building Columns 10 minutes
Overview
Students learn how to build columns, using the Build Attribute
transformer.
Launch
Suppose we want to transform our table, converting pounds
to kilograms
or weeks
to days
. The Build Attribute
transformer makes a new copy of a dataset, and adds a new attribute. We must provide a dataset, a name for the new attribute, an existing collection to add the attribute to, a formula for the attribute’s values, and an indication of the type of value the formula will evaluate to.
Investigate
-
Open the
Transformer
plugin, and choose the transformerBuild Attribute.
Selectanimals-dataset
. -
Enter
Young
as theName of New Attribute
. Selectcases
as theCollection to Add To
. In the formula expression box, typeAge < 5
. Apply the transformer. What happens? -
Now, enter
is-cat
as theName of New Attribute
and try typingSpecies = “cat”
in the formula expression box. What do you get? What do you think is going on?
The Build Attribute
Transformer walks through the table, applying whatever formula expression it was given to each row. Whatever the formula expression produces for that row becomes the value of our new column, which is named based on the string it was given. In the first example, we gave it Age < 5
, so the new table had an extra Boolean column for every animal, indicating whether or not it was young.
Synthesize
Debrief with students. Ask them if they can think of a situation where they would want to use this. Some ideas:
-
A dataset from Europe might list everything in metric (centimeters, kilograms, etc), so we could build a column to convert that to imperial units (inches, pounds, etc).
-
A dataset about schools might include columns for how many students are in the school and how many of those students identify as multi-racial. But when comparing schools of different sizes, what we really want is a column showing what percentage of students identify as multi-racial. We could use to compute that for every row in the table.
Being able to define is a huge upgrade in our ability to analyze data! But as a wise person once said, "with great power comes great responsibility"! Dropping all the dogs from our dataset might be a cute exercise in this class, but suppose we want to drop certain populations from a national census? Even a small programming error could erase millions of people, impact funding for things like roads and schools, etc.
🔗Additional Exercises:
These materials were developed partly through support of the National Science Foundation,
(awards 1042210, 1535276, 1648684, and 1738598).
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 contact@BootstrapWorld.org.