Students learn more about Transformers, including Transform Attribute
and Build Attribute
.
Lesson Goals |
Students will be able to…
|
Student-facing Lesson Goals |
|
Materials |
|
🔗Transforming Columns 10 minutes
Overview
Students learn how to transform columns using the Transform Attribute
Transformer.
Launch
We’ve already explored the Filter
Transformer, which walks through a dataset, applying the Boolean expression that we give it to each row - and then creating a modified copy of our original dataset.
Suppose we want to transform our table in a different way!
-
Maybe we want to convert
Pounds
toKilograms
orWeeks
toDays
. -
Maybe we want to transform the
Pounds
column into aHeavy
column, which producestrue
orfalse
depending on if the animal is heavy.
The Transform Attribute
Transformer makes that possible!
Investigate
Like the Filter
Transformer, the Transform Attribute
Transformer walks through the table - but what the expression produces for each row becomes the value in a new column. We name that column when we create our Transform Attribute
Transformer.
Naming Transformers and Attributes
You may have noticed that when we create and save Transformers, we give them sensible names such as filter-is-cat
or filter-is-fixed
. The first part of the name comes from the type of Transformer, and the second part describes what the Transformer does.
In this lesson, students transform and build columns to create new attributes. These new attributes need sensible names, too! If we transform our Weeks
attribute to days (multiplying by 7), the new attribute name should be Days
. If we build a new attribute showing the animals’ weight in kilos, the new attribute should be called Kilos
.
Complete Transform Attribute in the Animals Starter File to explore how to create and apply a Transform Attribute
Transformer.
Synthesize
-
What are some situations where you would want to the
Transform Attribute
Transformer?-
A dataset from Europe might list everything in metric (centimeters, kilograms, etc), so we use
Transform Attribute
to convert 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
Transform Attribute
to compute that for every row in the table.
-
🔗Building Columns 10 minutes
Overview
Students learn how to build columns, using the Build Attribute
Transformer.
Launch
So far, we’ve used Transformers to filter and to transform an attribute. The other Transformer we are exploring today is called Build Attribute
.
Investigate
Now that you have some familiarity with creating and defining Transformers, let’s explore the Build Attribute
Transformer. Can you determine what it does?
It creates an additional column in the dataset, rather than transforming the existing column.
Complete Build Attribute in the Animals Starter File.
Synthesize
-
Can you think of any other situations where you would want to the
Build Attribute
Transformer? -
How is
Build Attribute
similar toTransform Attribute
? How are they different?-
Build Attribute
creates an additional column, using the expression that we provide.Transform Attribute
converts an existing column, using the expression that we provide.
-
-
When might it make more sense to build an attribute, rather than to transform it?
-
We would build rather than transform if we want to do comparisons across columns, or need to preserve the original column for any reason (e.g., we want measurements in metric and standard units.)
-
Being able to create and define a Transformer 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.
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927). 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.