Public
Edited
Sep 11, 2024
2 forks
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
allCarburants = {
const carburants = [];
dataset.forEach((item) => {
if (item.carburants_disponibles !== null) {
carburants.push(...item.carburants_disponibles)
}
})
return [...new Set(carburants)];
}
Insert cell
stationSummary = allCarburants
.map((nomCarburant) => {
const nbStations = dataset.filter((station) => station.carburants_disponibles !== null && station.carburants_disponibles.includes(nomCarburant)).length;
return { nom: nomCarburant, nbStations: nbStations };
})
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
dataset = {
// Récupération des données
const ds = await d3.json('https://data.economie.gouv.fr/api/explore/v2.1/catalog/datasets/prix-des-carburants-en-france-flux-instantane-v2/exports/json');

// Conversion des types avec forEach (modifie le jeu de données sur place)
// On utilise la même logique pour chacun des prix à convertir (avec un opérateur ternaire) :
// si on a un prix existant, on le transforme en nombre avec '+', sinon on conserve
// la valeur null.
ds.forEach((d) => {
d.sp95_prix = d.sp95_prix ? +d.sp95_prix : null;
d.gazole_prix = d.gazole_prix ? +d.gazole_prix : null;
d.e85_prix = d.e85_prix ? +d.e85_prix : null;
d.gplc_prix = d.gplc_prix ? +d.gplc_prix : null;
d.e10_prix = d.e10_prix ? +d.e10_prix : null;
d.sp98_prix = d.sp98_prix ? +d.sp98_prix : null;
});

// On retourne le jeu de données
return ds;
}
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