Out: February 28th
Project 1 Partner Form Deadline: March 1, 11:59PM EST
In: March 15th, 11:59PM EST
It's time to try your data science skills on real datasets! For this assignment, you will choose one of three datasets to work on. You'll then apply what we've learned so far to clean up the data, analyze the data, and write a report that presents the results of your analysis. There's no difference in difficulty across the datasets – we're merely letting you choose which dataset/question you are most interested in exploring.
The project occurs in two stages. During the first week, you'll work on the design of your tables and functions, reviewing your work with a TA during a Design Check. In the second week, you'll implement your design, presenting your results in a written report that includes charts and plots from the tables that you created. The report and the code you used to process the data get turned in for the Final Handin.
This is a pair project. You and a partner should complete all project work together. You can find your own partner or we can match you with someone. Note that you have to work with different partners on each of the three projects in the course.
https://hackmd.io/@cs111/table
Your dataset/question options are:
Whichever dataset you choose, you will be given a collection of questions to answer in your analysis. You will also provide a function (summary-generator
) that can be used to generate summary data about a specific aspect of your dataset. The summary-generator
function will allow the user to customize which statistic (such as average, sum, median) gets used to generate the table data.
Detailed instructions for accessing each dataset, and the corresponding analysis and summary requirements, are in the following expansion options. The rest of the handout (after the expansion options) explains general requirements that apply regardless of which option you have chosen.
We suggest skimming the instructions for your chosen dataset, and then reading the design check instructions, and then reading the instructions for your chosen dataset in detail. The overarching goal of this project is to answer the analysis questions and to write and test the summary-generator
function, and the rest of this handout walks you through those goals. We expect that the specific analysis questions and summary-generator
function description will take a few read-throughs to thoroughly understand, and that you'll switch between the general instructions and the specific instructions for your dataset while making your design check plan. Do not worry if you and your partner do not immediately arrive at the list of tasks you need to do in order to complete the project – one of the skills you are practicing is how to break a large analysis down into smaller steps. The design check with your TA will be one opportunity to let you know if you are on the right track.
Overview: This dataset covers country-level carbon emissions and climate change measurements since 1960. The main table in this dataset (co2-emissions-table
) gives the total and per-capita emissions for every country and year in the dataset. You are also given a table of all years from 1960 until the end of the dataset, a table of all regions, and a table that has a row for each country with the region it is in and its cumulative warming in degrees since 1960. Take a minute to load the tables (using the stencil code below) into Pyret and take a look at the contents of each table before continuing reading this section.
Analysis: If you choose this dataset, your analysis should answer the following questions about the CO2 Emissions data: All analysis questions should be answered with both a visualization/chart and corresponding table
warming-deg-c-table
) had the highest cumulative CO2 emissions since 1960?
Note: Use the following function that's included in your stencil code instead of Pyret's builtin string-to-number
function! Take a look at the where
block to see how it is used.
Summary Generator: You will also create a summary-generator
function that can be used to generate summaries of country-level emissions and warming datasets.
Imagine that there are multiple country-level emissions and warming datasets starting in 1960, and that you need to create summaries of them with different types of statistics. For example, in one case, you may get the dataset from 1960 through 2020 and need to find the total CO2 emissions over all years in the time period, over all of the countries in each region. Or in another case, you may get the dataset with a different set of years or countries, and need to find the average CO2 emissions over all years in the time period, over all of the countries in each region. This all requires building a function that is flexible in terms of which data it presents and what kind of statistics it computes.
Your summary-generator
will take in a table that contains the following columns:
For example, the input table might look like
The summary-generator
will also take in a summary function. Take a look at the functions (sum
, mean
, etc) on the summary function documentation. Each takes in a Table
and String
representing a column name, and applies the relevant math over that column of the table to produce a single Number
(for example, mean
produces the mean of all of the values in the column).
The goal of your summary-generator
is to figure out how to use the summary function and the input table to produce an output table with only these columns: "region", "avg-warming", and "CO2-summary":
Each row represents the statistics for a single Region. The avg-warming
column contains the average warming across all countries on that continent since 1960. The "region" and "avg-warming" columns will be the same for a given input table, no matter what summary function you give to your summary-generator
. The CO2-summary
column summarizes some statistic about the emissions per year across countries in the region since 1960, based on the summary function input. The CO2 statistic might be the total, average, median, etc emissions across countries in each region.
For instance, if the mean
function were passed into your summary-generator
function, the CO2-summary
column should contain the average CO2 emissions over all years of the data set, over all of the countries in that region. If the sum
function were passed into your summary-generator
function, the CO2-summary
column should contain the total CO2 emissions over all years of the data set, over all of the countries in that region.
For the summary-generator
function, use the following header:
This might be called as summary-generator(mytable, sum)
or summary-generator(mytable, mean)
to summarize the total or average CO2 emissions since 1960 across countries in each region as represented in mytable
.
Note: sum
and mean
here are built-in functions (that you do not write), as described above. Passing a function as an argument is like what you have done when using or table operations like build-column
, filter-with
, and transform-column
.
Your summary-generator
function should not reference any tables from outside the function except the provided regions-table
. While producing your output table, you should use regions-table
as a starting point (to build columns for the output table and to extract data from the input table t
). Also, your output table should not contain any columns other than those shown in the example above: "region", "avg-warming", and "CO2-summary".
Note: You do not need to test summary-generator
. However, please run summary-generator
twice outside of the function with two different summary functions. Make sure the output makes sense! This will look something like this:
Hints:
summary-generator
.Table
and a String
. For each region, what does the input table to the summary function look like in order to get the desired output? It may help to draw out an example table for a specific region. Then, think about how you to create those Table
s out of the input table to summary-generator
.summary-generator
to answer some of those questions? What summary functions would you use? Understanding this question will go a long way in helping you understand the goal of the summary-generator
function and the entire assignment.Copy and paste the following code to load the datasets into Pyret.
Overview: This dataset covers customers' starting and stopping zip codes for a bikshare service. The data was collected over October 2020. The main table in this dataset (october-2020-citibike-table
) shows information about the start/stop bikeshare stations customers have used and trip duration, as well as the age/gender of customers. Additionally, we include a table with the zipcodes of each bikeshare station, and a table of all zipcodes. Take a minute to load the tables (using the stencil code below) into Pyret and take a look at the contents of each table before continuing reading this section.
Analysis: If you choose this dataset, your analysis should answer the following questions about the bikeshare data: All analysis questions should be answered with both a visualization/chart and corresponding table
Summary Generator: You must now create a summary-generator
function that can be used to generate summaries of bikeshare datasets.
Imagine that there are many bikshare datasets, and that you need to create summaries of them with different types of statistics. For example, in one case, you may get the dataset from 2019 and need to find the average ride duration for each zipcode. Or in another case, you may get the dataset from 2022 and need to find the median ride duration for each zipcode. This all requires building a function that is flexible in terms of which data it presents and what kind of statistics it computes.
Your summary-generator
will take in a table with the following columns:
For example, the input table might look like
The summary-generator
will also take in a summary function. Take a look at the functions (sum
, mean
, etc) on the summary function documentation. Each takes in a Table
and String
representing a column name, and applies the relevant math over that column of the table to produce a single Number
(for example, mean
produces the mean of all of the values in the column).
The goal of your summary-generator
is to figure out how to use the summary function and the input table to produce an output table with only these columns: "zipcode", "average-age", and "duration-summary":
Each row has data for a particular zipcode. The average-age
column contains the average age of the riders for each ride that started or ended in that zipcode. The zipcode
and average-age
columns will be the same for a given input table, no matter what summary function you give to your summary-generator
. The duration-summary
column summarizes some statistic about the durations of the unique rides around that zipcode, based on the summary function input. The duration-summary
statistic might be the total duration, the average duration, the median, and so on.
For instance, if the mean
function were passed into your summary-generator
function, the duration-summary
column should contain the average duration over all rides of the data set. If the sum
function were passed into your summary-generator
function, the duration-summary
column should contain the total duration over all rides of the data set.
For the summary-generator
function, use the following header:
This might be called as summary-generator(mytable, sum)
or summary-generator(mytable, mean)
to summarize the total or average duration of rides in each zipcode represented in mytable
.
Note: sum
and mean
here are built-in functions (that you do not write), as described above. Passing a function as an argument is like what you have done when using or table operations like build-column
, filter-with
, and transform-column
.
Your summary-generator
function should not reference any tables from outside the function except the provided sorted-zip-codes-table
. While producing your output table, you should build columns to sorted-zip-codes-table
. Also, your output table should not contain any columns other than those shown in the example above: "zipcode", "average-age" and "duration-summary".
Note: You do not need to test summary-generator
. However, please run summary-generator
twice outside of the function with two different summary functions. Make sure the output makes sense! This will look something like this:
Hints:
summary-generator
.Table
and a String
. For each zipcode, what does the input table to the summary function look like in order to get the desired output? It may help to draw out an example table for a specific zipcode. Then, think about how you to create those Table
s out of the input table to summary-generator
.summary-generator
to answer some of those questions? What summary functions would you use? Understanding this question will go a long way in helping you understand the goal of the summary-generator
function and the entire assignment.Copy and paste the following code to load the datasets into Pyret.
Overview: This dataset covers the county-level quantities of grocery and convenience stores, as well as county populations. The main table (county-store-count-table
) shows the numbers of grocery and convenience stores in counties. You are also given a table with the populations of counties, as well as a table of state abbreviations. Take a minute to load the tables (using the stencil code below) into Pyret and take a look at the contents of each table before continuing reading this section.
Analysis: If you choose this dataset, your analysis should answer the following questions about the grocery and population data: All analysis questions should be answered with both a visualization/chart and corresponding table
Note: "combined stores" here refers to the sum of grocery and convenience stores.
Summary Generator: You must now create a summary-generator
function that can be be used to generate summaries of county-level store datasets.
Imagine that there are many county-level store datasets in the US, and that you need to create summaries of them with different types of statistics. For example, in one case, you may get the dataset from 1970 and need to find the maximum stores-per-capita value for counties in each state. Or in another case, you may get the dataset from 2021 and need to find the average stores-per-capita for counties in each state. This all requires building a function that is flexible in terms of which data it presents and what kind of statistics it computes.
Your summary-generator
will take in a table that contains the following columns:
For example, the input table might look like
The summary-generator
will also take in a summary function. Take a look at the functions (sum
, mean
, etc) on the summary function documentation. Each takes in a Table
and String
representing a column name, and applies the relevant math over that column of the table to produce a single Number
(for example, mean
produces the mean of all of the values in the column).
The goal of your summary-generator
is to figure out how to use the summary function and the input table to produce an output table with only these columns: "state", "abbv", "num-stores", and "per-capita-summary":
Each row is a State. The num-stores
column contains the total number of grocery and convenience stores in that state. The "state", "abbv" and "num-stores" columns will be the same for a given input table, no matter what summary function you give to your summary-generator
. The per-capita-summary
column summarizes some statistic about the total number of stores (grocery and convenience) per capita across counties in that state, , based on the summary function input. The per-capita statistic might be the total, average, median, etc stores per capita across counties in that state.
For instance, if the mean
function were passed into your summary-generator
function, the per-capita-summary
column should contain the average value of total stores per capita across all counties in the state for that row. If the sum
function were passed into your summary-generator
function, the per-capita-summary
column should contain the sum of the total stores per capita across all the counties in that state.
The person who calls your summary-generator
function will indicate which summary method to use by passing another function as input.
For the summary-generator
function, use the following header:
This might be called as summary-generator(mytable, sum)
or summary-generator(mytable, mean)
to summary the total or average CO2 emissions since 1960 across countries in each region as represented in mytable
.
Note: sum
and mean
here are built-in functions (that you do not write), as described above. Passing a function as an argument is like what you have done when using or table operations like build-column
, filter-with
, and transform-column
.
Your summary-generator
function should not reference any tables from outside the function except the provided state-abbv-table
. While producing your output table, you should use state-abbv-table
as a starting point (to build columns for the output table and to extract data from the input table t
). Also, your output table should not contain any columns other than those shown in the example above: "state", "abbv", "num-stores" and "per-capita-summary"
Note: You do not need to test summary-generator
. However, please run summary-generator
twice outside of the function with two different summary functions. Make sure the output makes sense! This will look something like this:
Hints:
summary-generator
.Table
and a String
. For each state, what does the input table to the summary function look like in order to get the desired output? It may help to draw out an example table for a specific state. Then, think about how you to create those Table
s out of the input table to summary-generator
.summary-generator
to answer some of those questions? What summary functions would you use? Understanding this question will go a long way in helping you understand the goal of the summary-generator
function and the entire assignment.Copy and paste the following code to load the dataset into Pyret:
The design check is a 30-minute one-on-one meeting between your team and a TA to review your project plans and to give you feedback well before the final deadline. Many students make changes to their designs following the check: doing so is common and will not cost you points.
Task – Find a Partner and Signup for a slot
Task – Understand your data: use the stencil code to load the data set into Pyret. Look at the structure and contents of each provided table. In one place, create a reference sheet that you can refer to for the rest of the project and bring to the design check. We suggest putting the following on the reference sheet:
summary-generator
function for your dataset.Making a reference sheet like this will save you time as you consider the questions, make a design check plan, and start coding!
You should plan to bring your reference sheet to any office hours that you attend for this project.
Task – Data-cleaning plan: Look at your datasets and identify the cleaning, normalization, and other pre-processing steps that will need to happen to prepare your datasets for use. Make a list of the steps that you'll need to perform, with a couple of notes about how you will do each step (which table operation, whether you need helper functions, etc).
Task – Analysis plan: For each of the analysis questions listed for your dataset, describe how you plan to do the analysis. You should try to answer these questions:
filter-with
, build-column
and transform-column
). Make sure to list all Pyret operators, functions (with input/output types and description of what they do, but without the actual code). If you don't know how to create any table, discuss it with the TA at your design check.Sample Answer:
Assume you had a dataset with information on changes in city populations over time. If you were asked to analyze whether cities with population (in 2000) larger than 30,000 have an increase or decrease in population, your answer to this design-check question might be:
"I'd start with a table of cities that have a population in 2000 of over 30,000, and then make a scatterplot of the population of those cities in 2000 and 2010. I'd add a linear regression line, then check whether there was a pattern in changes between the two population values. I'd obtain a table of cities with a population of greater than 30,000 in 2000 by using the filter-with
function."
Task – summary-generator
function example: Write a check
block with two examples for your summary-generator
function. Detailed instructions about this function are included in the Instructions section for your dataset. Also, write down some concrete ideas for how you will produce this function. This means that you'll have to create example input tables – use your reference sheet from the first task as a starting point!
By 11:59pm the day before your design check starts, submit your work for the design check as a PDF file named project-1-design-check.pdf
to "Project 1 Design Check" on Gradescope. Please add your project partner to your submission on Gradescope as well. You can create a PDF by writing in your favorite word processor (Word, Google Docs, etc) then saving or exporting to PDF. Ask the TAs if you need help with this. Please put both you and your partner's login information at the top of the file.
Your design check grade will be based on whether you had viable ideas for each of the questions and were able to explain them adequately to the TA (for example, we expect you to be able to describe why you picked a particular plot or table format). Your answers do not have to be perfect, but they do need to illustrate that you have thought about the questions and what will be required to answer them (functions, graphs, tables, etc.). The TA will give feedback for you to consider in your final implementation of the project.
Your design check grade will be worth roughly a third of your overall project grade. Failure to account for key design feedback in your final solution may result in a deduction on your analysis stage grade.
Note: We believe the hardest part of this assignment lies in figuring out what analyses you will do and in creating the tables you need for those analyses. Once you have created the tables, the remaining code should be similar to what you have written for homework and lab. Take the Design Check seriously. Plan enough time to think out your table and analysis designs.
The deliverables for this stage include:
analysis.arr
that contains the function summary-generator
, the tests for the function, and all the functions used to generate the report (charts, plots, and statistics).report.pdf
. Include in this file the copies of your charts and the written part of your analysis. Your report should address each of the analysis questions outlined for your chosen dataset. Your report should also contain responses to the Reflection questions described below.Note: Please connect the code in your analysis
file and the results in your report
with specific comments and labels in each. For example:
Sample Linking: See the comment in the code file:
Then, your report might look like this:
In order to do these analyses, you will need to combine data from the multiple tables in your chosen dataset. For each dataset/problem option, the tables use slightly different formats of the information used to link data across the tables (such as different date formats). You should handle aligning the datasets in Pyret code, not by editing the Google Sheets prior to loading them into Pyet. Making sure you know how to use coding to manage tables for combining data is one of our goals for this project. Pyret String documentation might be your friend!
Hint: If you feel your code is getting too complicated to test, add helper functions! You will almostly certainly have computations that get done multiple times with different data for this problem. Create and test a helper or two to keep the problem manageable. You don't need helpers for everything, though – for example, it is fine for you to have nested build-column
expressions in your solution. Don't hesitate to reach out to us if you want to review your ideas for breaking down this problem.
This is where your summary sheet from the first design step task will come in handy! Feel free to add the helper function descriptions to that sheet, and visually show how the helper functions fit together and make use of all of the different tables.
Your report should contain any relevant plots (and tables, if you find them helpful as well), any conclusions you have made, and your reflection on the project (see next section). We are not looking for fancy or specific formatting, but you should put some effort into making sure the report reads well (use section headings, full sentences, spell-check it, etc). There's no specified length – just say what you need to say to present your analyses.
Note: Pyret makes it easy to extract image files of plots to put into your report. When you make a plot, there is an option in the top left hand side of the window to save the chart as a .png
file which you can then copy into your document. Additionally, whenever you output a table in the interactions window, Pyret gives you the option to copy the table. If you copy the table into some spreadsheet, it will be formatted as a table that you can then copy into Word or Google Docs.
Have a section in your report document with answers to each of the following questions after you have finished the coding portion of the project:
For your final handin, submit one code file named analysis.arr
containing all of your code for producing plots and tables for this project. Also submit report.pdf
, which contains a summary of the plots, tables, and conclusions for your answers to the analysis questions. Your project reflection also should be in the report file. Nothing is required to print in the interactions window when we run your analysis file, but your analysis answers in report.pdf
should include comments indicating which variable names or expressions in analysis.arr
yield the data for your answers.
You will be graded on Functionality, Design, and Testing for this assignment.
Functionality – Key metrics:
summary-generator
function working?Testing – Key metrics:
Design – Key metrics:
You can pass the project even if you either (a) skip the summary-generator
function or (b) have to manipulate some of the tables by hand rather than through code. A project that does not meet either of these baseline requirements will fail the functionality portion.
A high score on functionality will require that you wrote appropriate code to perform each analysis and wrote a working summary-generator
function. The difference between high and mid-range scores will lie in whether you chose and used appropriate functions to produce your tables and analyses.
For design, the difference between high and mid-range scores will lie in whether your computations that create additional tables are clear and well-structured, rather than appearing as you made some messy choices just to get things to work.
Brown University CSCI 0111 (Spring 2022)
Do you have feedback? Fill out this form