Unlisted
Edited
Apr 27
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
popArray
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
population = aq.from(popArray)
Insert cell
population
.sample(6)
.view()
Insert cell
Insert cell
Insert cell
// For example, we only want the year and number of people
population.select('year', 'age').view(6)
Insert cell
Insert cell
// For example, we only want the population in 1960
// Table expressions
// popArray.filter(d => d.year === 1960) // <--------Array
population.filter(d => d.year === 1960)
Insert cell
threshold = 2000000
Insert cell
population
.params({ threshold: threshold })
.filter((d, $) => d.people > $.threshold)
Insert cell
Insert cell
// We want to sort the data by year. By year and age?
population.orderby('year', aq.desc('age')).view()
Insert cell
Insert cell
// "roll up" or "reduce" a column into a single summarizing value
population
.groupby('age', 'sex')
.rollup({ mean: d => op.mean(d.people) })
.view()
Insert cell
Insert cell
// Total number of people each year
Insert cell
// Total number of people of each age group each year
Insert cell
Insert cell
Insert cell
population.view(5)
Insert cell
countries
.view(10)
Insert cell
// Join the datasets based on year
population.join(countries, 'year').view()
Insert cell
// What if the column names were not the same?
{
const temp = countries.rename({'year': 'Year of data collection'})

// Tell it what the column name is on left and right, and also tell it which columns to include in the output
return population
.join(temp,
['year', 'Year of data collection'],
[aq.all(), aq.not('Year of data collection')]
)
.view(6)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Computing means
Insert cell
Insert cell
// Filtering for months where it rained
Insert cell
Insert cell
// Scatterplot
Insert cell
Insert cell
Insert cell
// Fold an array of columns, { as: key, value }
weather1.fold(['temp', 'precip', 'wind'], { as: ['weather_element', 'value'] }).view()
Insert cell
Insert cell
Insert cell
// Group by the columns you want to keep
// pivot — tell it which column should turn into new columns, and which column should turn into values
weather2
.groupby('month')
.pivot('weather_element', 'value').view()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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