Public
Edited
Apr 27, 2023
Insert cell
Insert cell
years = Array.from({length:17},(d,i) => new Date(0).getFullYear()+36+i)
Insert cell
yearsKey = years.map(y => `year_${y}`)
Insert cell
data = new Object // you have to define data as an object first
Insert cell
yearsKey.map(k => data[k]= []) // you have to define data.year as an array first
Insert cell
Insert cell
fragileStatesIndex0 = await FileAttachment("2006-fragile states index.xlsx").xlsx()
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
Insert cell
Insert cell
flags = await FileAttachment("Flags_colors-7.csv").csv()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
raw_data = [year_2006, year_2007, year_2008, year_2009, year_2010, year_2011, year_2012, year_2013, year_2014, year_2015, year_2016, year_2017, year_2018, year_2019, year_2020, year_2021, year_2022]
Insert cell
raw_data.map((yearData,y) => yearData.slice(1).map((obj,i) => data[yearsKey[y]][i] = new Object))
Insert cell
raw_data.map((yearData,y) => yearData.slice(1).map((d,i) => Object.keys(d).map((key,j) => data[yearsKey[y]][i][keys[j]] = d[key])))
Insert cell
data
Insert cell
flag_colours = new Object
Insert cell
flags.filter(d => d.value !== "").map(d => flag_colours[d.source.match(/\w+/)] = new Set) // I cant see any benefit from Wrangler. Why the wrangling is not stable and usable on other parts?!?!?! So I'm using the flags database
Insert cell
flags.filter(d => d.value !== "").map(d => flag_colours[d.source.match(/\w+/)].add(d.target)) // use .match to get rid of the flag icon in keys
Insert cell
Object.keys(flag_colours).map(country => flag_colours[country] = [...flag_colours[country]])// to convert each Set to an Array
Insert cell
flag_colours
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data
Insert cell
Insert cell
tables_aq = new Object
Insert cell
yearsKey.map(y => tables_aq[y] = aq.from(data[y])) // generate aquero table data for each year and hold it together in tables_aq
Insert cell
tables_aq // aquero table data for all years
Insert cell
viewof yearInput = Inputs.select(years, {label: "Select the year"})
Insert cell
tables_aq[`year_${yearInput}`].view() // visualise the selected year's tabular data with aquero .view()
Insert cell
Insert cell
table_plot_input = data[`year_${yearInput}`] // for using Plot table you should have year_data as a separate database ready first.
Insert cell
table_plot_input
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
data_aq = new Object
Insert cell
yearsKey.map(year => data_aq[year] = tables_aq[year].objects()) // access the wrangled data by aquero via .objects()
Insert cell
data_aq // whatever wrangling you do with aquero will be reflected in this dataset. use this for d3. // NO you cannot use this. the wrangling stuff does not store in the table_aq and therfore not reflected in data_aq either. you have to store it while doing wranglings...
Insert cell
tables_aq[`year_${yearInput}`]
.derive({Year: aq.escape(d => d.Year.getFullYear())})
.derive({Rank: aq.escape(d => d.Rank.match(/\d+/).toString())}) // use aq.escape( d => ...) wherever you need to use other parameters or functions not supported by arquero
.view()
Insert cell
aq_wrangled_data = new Object
Insert cell
aq_wrangled_data[`year_${yearInput}`] = tables_aq[`year_${yearInput}`]
.derive({Year: aq.escape(d => d.Year.getFullYear())})
.derive({Rank: aq.escape(d => d.Rank.match(/\d+/).toString())})
.objects() // STORE data from aquero table wrangling. the wrangling is not reflected in the main tables_aq database automatically.
Insert cell
aq_wrangled_data // as you select different years in the INPUT, you generate the whole database for aq_wrangled_data for al years.
Insert cell
Insert cell
Wrangler(data[`year_${yearInput}`]) // Create an interface to wrangle your data
Insert cell
viewof wrangled = Wrangler(data[`year_${yearInput}`]) // Create a view of the wrangled data
Insert cell
wrangled.data // returns an arquero table, you can call .view() or .objects()
Insert cell
wrangled.code // access the code as a string
Insert cell
wrangled.inputs // access the current inputs configuration
Insert cell
// flags_colours = // To use copied code replace "data" with your own variable
// aq.from(flags)
// .fold('target')
// .groupby('source')
// .filter(d => d["value"] !== " ")
// .select('source','value')
// .orderby("source")
// .objects() // Uncomment to return an array of objects
Insert cell
Flags_colors-7.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
country_group = d3.group(flag_file, c => c.Country)
Insert cell
country_group.get("🇦🇩 Andorra")
Insert cell
import {aq, op} from "@uwdata/arquero"
Insert cell
import {Wrangler, op} from "@observablehq/data-wrangler"
Insert cell
d3 = require("d3")
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