Public
Edited
May 24
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {vl} from "@vega/vega-lite-api-v5"
Insert cell
import {aq, op} from "@uwdata/arquero"
Insert cell
Insert cell
co2_emissions_data = FileAttachment("co2_pcap_cons.csv").csv()
Insert cell
co2_table = aq.from(co2_emissions_data)
Insert cell

// Generate an array of year strings from 1950 to 2022
yearColumns = Array.from({ length: 2022 - 1940 + 1 }, (_, i) => (1940 + i).toString());


Insert cell
result_co2 = co2_table
.fold(yearColumns, { as: ["year", "value"] }) // Fold years into two columns
.groupby("country") // Group by country
.rollup({ avg_value: d => op.mean(d.value) }); // Compute average value per country

Insert cell
top5_2022 = co2_table
.derive({ emissions_2022: d => +d["2022"] })
.orderby(aq.desc("emissions_2022")) //pause why is it doing the opposite ??
.slice(0,5)

Insert cell

longFormat_2022 = top5_2022
.fold(yearColumns, { as: ['year', 'co2_emissions'] })


Insert cell
annual_co2 = FileAttachment("annual-co2-emissions-per-country.csv").csv()
Insert cell
annual_co2_table = aq.from(annual_co2)
Insert cell
excludedEntities = ['World', 'Non-OECD', 'Asia', 'Asia (GCP)', 'Upper-middle-income countries', 'High-income countries', 'OECD (GCP)', 'Asia (excl. China and India)', 'North America', 'North America (GCP)', 'Lower-middle-income countries', 'Europe', 'Europe (GCP)', 'European Union (28)', 'European Union (27)', 'Middle East (GCP)', 'Europe (excl. EU-27)', 'Europe (excl. EU-28)', 'Africa', 'Africa (GCP)', 'North America (excl.USA)', 'South America', 'South America (GCP)']
Insert cell
top_5_emitters = annual_co2_table
.filter(d => d.Year === '2022'&& d.Code !== null && d.Code !== '' && d.Entity != 'World') // only countries
.derive({ emissions: d => +d['Annual CO₂ emissions'] }) // force numeric
.orderby(aq.desc('emissions'))
.slice(0, 5);
Insert cell
top_5_codes = top_5_emitters.array('Code');


Insert cell
filtered_data = annual_co2_table
.filter(aq.escape(d => top_5_codes.includes(d.Code) && d.Year >= 1940 && d.Year % 5 === 0))

Insert cell
filtered_data.filter(d => d.Year < 1970).view();

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