Public
Edited
Mar 4, 2023
3 forks
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
san_diego_stops = fetch(
"https://s3.amazonaws.com/working-with-data.recoveredfactory.net/stops_2022.json"
).then((response) => response.json())
Insert cell
san_diego_stops
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
function graphql(payload, headers = {}) {
headers["content-type"] = "application/json";
return fetch("https://ohiocourts.hasura.app/v1/graphql", {
body: JSON.stringify(payload),
headers: headers,
method: "POST",
mode: "cors"
})
.then((response) => {
return response.json();
})
.then((jsonData) => {
return jsonData.data;
});
}
Insert cell
cases_judges = graphql({
operationName: "MyQuery",
query: `
query MyQuery {
cases {
case_year
judge
arresting_agency
}
}
`
})
Insert cell
Insert cell
Insert cell
Insert cell
test@2.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
variables = ["B01003_001E"]
Insert cell
Insert cell
url = `https://api.census.gov/data/2021/acs/acs5?get=NAME,${Array.from(variables.values())}&for=place:04416&in=state:39`
Insert cell
census_data = d3.json(url)
Insert cell
Insert cell
Insert cell
cases_judges_dt
.view()
Insert cell
Inputs.table(cases_judges_dt)
Insert cell
cases_judges_dt = aq.from(cases_judges.cases)
Insert cell
import { aq, op } from "@uwdata/arquero"
Insert cell
Insert cell
Insert cell
cases_judges_dt
.groupby("arresting_agency")
.count()
.orderby(aq.desc("count"))
.view()
Insert cell
Insert cell
Insert cell
my_little_function=a=>a+2
Insert cell
my_little_function(2)
Insert cell
function hello_world(world){return "hello "+world;}
Insert cell
hello_world("ilica")
Insert cell
Insert cell
url_2 =(place_name)=> `https://api.census.gov/data/2021/acs/acs5?get=NAME,${Array.from(variables.values())}&for=place:${place_name_to_fips.get(place_name)}&in=state:39`
Insert cell
get_population=(place_name)=>d3.json(url_2(place_name))
Insert cell
get_population("OAKWOOD VILLAGE")
Insert cell
Insert cell
Insert cell
cases_judges_dt
.groupby("arresting_agency", "case_year")
.count()
//here's us using a function! The input will always be the row, so we need to specify what to do with that row! Filter filters to the rows that eval as true!
// So here we are saying -> take every row, find the case year column, and check if it matches 2021
.filter(d=>d.case_year==2021)
.orderby(aq.desc("count"))
.view()
Insert cell
Insert cell
viewof selected = Inputs.select(cases_judges_dt.columnNames())
Insert cell
cases_judges_dt
.params(selected)
.groupby(selected)
.count()
.orderby(aq.desc("count"))
.view()
Insert cell
Insert cell
cases_judges_dt
.groupby("arresting_agency", "case_year")
// Here is the full form of count!
.rollup({county:op.count()})
.orderby(aq.desc("county"))
.view()
Insert cell
Insert cell
cases_judges_dt
.groupby("arresting_agency", "case_year")
.count()
.groupby("arresting_agency")
.rollup({avg:d=>op.mean(d.count)})
.orderby(aq.desc("avg"))
.view()
Insert cell
Insert cell
Insert cell
cases_judges_dt
.groupby("arresting_agency", "case_year")
.count()
.filter(d=>d.case_year==2021)
.join(
cases_judges_dt
.groupby("arresting_agency", "case_year")
.count()
.filter(d=>d.case_year==2016),
"arresting_agency")
.derive({pct_increase: d=>(d.count_1-d.count_2)*100/d.count_2})
.orderby(aq.desc("pct_increase"))
.filter(d=>d.count_1+d.count_2>100)
.view()
Insert cell
Insert cell
cases_judges_dt
.groupby("arresting_agency", "case_year")
.count()
.filter(d=>d.case_year==2021)
.derive({arresting_agency:d=>op.replace(d.arresting_agency," POLICE","")})
.derive({pop_arr:aq.escape(d=>all_outputs.get(d.arresting_agency))})
.derive({count_to_pop:d=>d.count/d.pop_arr})
.filter(d=>d.count_to_pop)
.orderby(aq.desc("count_to_pop"))
.view()
Insert cell
Insert cell
all_outputs =
new Map(await Promise.all(
all_arresting_agencies
.map(d=>d.arresting_agency)
.map(async (d)=>{
const data = await get_population(d);
return [d, data && data[1][1]]
})
))
Insert cell
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