Public
Edited
Apr 17, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// clean up process for benefits
viewof benefits = aq.from(clean)
.select('company', 'benefits') // select these columns only
.derive({
num_benefits: aq.escape( d => d3.count(d.benefits) ) // get a count of benefits by row
})
.dedupe('company','benefits') // deduplicate rows with the same benefit list
.filter(d => d.num_benefits > 0) // remove those without benefits (for other purposes, this might be useful)
// below is the part where I very ungracefully work with the arrays
// starts here
.derive({
benefits: d => op.replace(d.benefits, "['", "")
})
.derive({
benefits: d => op.replace(d.benefits, "']", "")
})
.derive({
benefits: d => op.replace(d.benefits, /'/g, "")
})
// ends here ^
.groupby('company') // once the array is clean, group all benefits by company
.rollup({
all_benefits: d => op.array_agg(d.benefits) // one company, one array of benefits
})
.derive({
all_benefits: d => op.split(d.all_benefits, ',')
})
.unroll('all_benefits') // do one company and one benefit per row
.derive({
all_benefits: d => op.trim(d.all_benefits)
})
.dedupe('company', 'all_benefits') // remove duplicates that resulted from the above
.rename({all_benefits: 'benefit'})
.view()
Insert cell
viewof unique_benefit_list = benefits
.select(1)
.dedupe()
.orderby('benefit')
.view()
Insert cell
Insert cell
// what companies offer benefits related to the benefits of interest?
viewof focus_benefits = benefits
// @Gretchen, you can add/remove benefits below if you'd like to explore others
.filter(d => d.benefit == 'Free or subsidised travel' || d.benefit == 'Company car')
.view()
Insert cell
// how many companies include the benefits in focus?
viewof focus_benefits_count = focus_benefits
.select('company')
.dedupe()
.count()
.view()
Insert cell
// how many of the companies that include the benefits in focus are part of the top companies?
focus_benefits
.filter(aq.escape(d => top_companies.includes(d.company)))
.view()
// nada :(
Insert cell
// what percent of the companies out of the whole dataset include the focused benefits?
viewof percent_benefits = benefits
.select('company')
.dedupe()
.count()
.rename({count: 'total number of companies'})
.derive({
percent_with_focus_benefits: aq.escape( d => focus_benefits_count.get('count',0) / d['total number of companies'] )
})
.view()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof clean_count_time_week = clean_count_overtime
.derive({date: d => op.parse_date(d.date)})
.derive({
week_date: aq.escape( d => d3.utcMonday(d.date) )
})
.groupby('week_date', 'company')
.rollup({
count: d => op.sum(d.count)
})
.groupby('week_date')
.derive({
percent: d => d.count/op.sum(d.count)
})
// .filter(d => +d.week_date == +op.utcdatetime(2023,1,27))
// .rollup({
// percent: d => op.sum(d.percent)
// })
.view()
Insert cell
top_companies = clean_count_overtime
.groupby('company')
.rollup({
count: d => op.sum(d.count)
})
.orderby(aq.desc('count'))
.filter(d => op.rank() <= 15)
.array('company')
Insert cell
palettes
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof titles = aq.from(raw_data)
// .derive({
// date: d => op.parse_date(d.date)
// })
.select('job_title', 'company')
.dedupe()
.view()
Insert cell
import {us} from "@observablehq/build-your-first-choropleth-map-with-observable-plot"
Insert cell
states = topojson.feature(us, us.objects.states)
Insert cell
nation = topojson.feature(us, us.objects.nation)
Insert cell
counties_ = topojson.feature(us, us.objects.counties)
Insert cell
viewof clean_count_overtime = aq.from(raw_data)
.derive({date: d => op.parse_date(d.date)})
.groupby('date', 'company')
.count()
.orderby('date')
.view()
Insert cell
Insert cell
viewof clean = aq.from(raw_data)
.derive({date: d => op.parse_date(d.date)})
// .filter(d => d.company == 'Uber Drivers')
.view()
Insert cell
clean
.select('geo_city', 'geo_state')
.dedupe()
.view()
Insert cell
zip_codes = d3.csvParse(data)
Insert cell
prox_url = 'https://corsproxy.io?' + encodeURIComponent(v_data['zipcodes.csv'].url)
Insert cell
data = fetch(prox_url).then(response => response.text())
Insert cell
raw_data = file.csv({typed: false})
Insert cell
Insert cell
Insert cell
Insert cell
zip_map = new Map(zips.map(d => [d.zip_code, d]))

//broadband_access_2018 = new Map(us_broadband_2018.map(({id, broadband}) => [id, broadband]))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// this is a really cool way of displaying tables. Much more aesthetically pleasing than the defaults of arquero and input.table

import { formatTable } from "@saneef/pretty-tables"
Insert cell
Insert cell
Insert cell
Insert cell
date_parser = d3.utcParse('%m/%d/%Y')
Insert cell
Insert cell
appcast_color_palette = ['#3138BB', '#FF7D6F', '#AF9BFC', '#C7FFE2', '#127FFC', '#FF9B77']
Insert cell
Insert cell
// sample of how to place html blocks in a grid

// html `<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; column-gap: 0px; row-gap: 5px;">
// ${viewof spend}
// ${viewof cpl}
// ${viewof cpc}
// </div>`
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