Published
Edited
Jan 6, 2021
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
// Load the protests.csv data (a File Attachment) into a variable
protests = FileAttachment("protests.csv").csv()
Insert cell
// How many protests are in the dataset?
num_protests = REPLACE_ME
Insert cell
Insert cell
// How much information is available about each protest?
num_features = REPLACE_ME
Insert cell
Insert cell
Insert cell
// Create an array of the number of attendees in each protest
// (make sure to return a *number* for each element in the array)
num_attendees = REPLACE_ME
Insert cell
Insert cell
// What is the lowest number of attendees?
min_attendees = REPLACE_ME
Insert cell
Insert cell
// What is the highest number of attendees?
max_attendees = REPLACE_ME
Insert cell
Insert cell
// What is the mean number of attendees?
mean_attendees = REPLACE_ME
Insert cell
Insert cell
// What is the median number of attendees?
median_attendees = REPLACE_ME
Insert cell
Insert cell
// What is the absolute difference between the mean and median number of attendees?
mean_median_diff = REPLACE_ME
Insert cell
Insert cell
Insert cell
// Create an array that holds the Location of each protest
locations = REPLACE_ME
Insert cell
Insert cell
// How many *unique* locations are in the dataset?
num_locations = REPLACE_ME
Insert cell
Insert cell
// How many protests occured in Washington?
// (hint: locations that end with "WA")
num_in_wa = REPLACE_ME
Insert cell
Insert cell
// What proportion of protests (number / total) occured in Washington?
prop_in_wa = REPLACE_ME
Insert cell
Insert cell
// How many protests occurred in each state?
// hint: use the d3.rollups method to create an *array of arrays*,
// where each one holds the state abbreviation and the number of protests in that state
// https://observablehq.com/@d3/d3-group
num_by_state = REPLACE_ME
Insert cell
Insert cell
// What was the highest number of protests that occured in a single state?
highest_in_a_state = REPLACE_ME
Insert cell
Insert cell
// Which state (two letter abbreviation) had the highest number of protests?
// hint: use the two variables calculated above
state_most_protests = REPLACE_ME
Insert cell
Insert cell
Insert cell
// Create an array that holds the Date of each protest
// You should convert the string in the original dataset to a proper date object using the Date() function
dates = REPLACE_ME
Insert cell
Insert cell
// What is the most recent date in the dataset?
most_recent = REPLACE_ME
Insert cell
Insert cell
// What is the earliest date in the dataset?
earliest = REPLACE_ME
Insert cell
Insert cell
// How many protests occurred in 2020?
// hint: use the getFullYear() method
num_in_2020 = REPLACE_ME
Insert cell
Insert cell
// How many protests occurred in 2019?
num_in_2019 = REPLACE_ME
Insert cell
Insert cell
// How many protests occurred in July (of any year)?
// Hint: you can use date.toLocaleDateString("default", { month: "long" }) to get the month name
num_in_july = REPLACE_ME
Insert cell
Insert cell
// How many protest occured each month?
// hint: use the d3.rollups method to create an *array of arrays*,
// where each one holds the month name and the number of protests in that month
by_month = REPLACE_ME
Insert cell
Insert cell
// Which month had the highest number of protests?
month_most_protests = REPLACE_ME
Insert cell
Insert cell
Insert cell
// How many different purposes are listed in the dataset?
// (the number of unique values of the `Event (legacy; see tags)` attribute)
num_purposes = REPLACE_ME
Insert cell
Insert cell
// That's quite a few -- if you look at the array, you'll notice
// a common pattern for each purpose. It's listed as:
// SOME_PURPOSE (additiona_detail)
// To get a higher level summary, create an array of `high_level_purposes` by
// extracting *everything before the first parenthesis* in each purpose ("Event (legacy; see tags)")
// You should return an array equal to the length of the protests dataset
high_level_purposes = REPLACE_ME
Insert cell
Insert cell
// Which high-level purpose was the most common?
// Hint, you may want to open a JavaScript statement to write multiple lines of code,
// Or try out d3.greatest with d3.rollups
// https://observablehq.com/@d3/d3-least
most_common_purpose = REPLACE_ME
Insert cell
Insert cell
Insert cell
import { check_answer, displayCaution } with {
answers
} from "@uw-info474/utilities"
Insert cell
answers = await FileAttachment("answers.json").json({ typed: true })
Insert cell
new Date(answers.earliest)
Insert cell
d3 = require("d3")
Insert cell
_ = require("lodash")
Insert cell
REPLACE_ME = undefined
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more