Public
Edited
Nov 29, 2023
Insert cell
Insert cell
coutriesEnergyRawData = FileAttachment("Energy data 1990 - 2020.csv").csv({typed:true})
Insert cell
coutriesEnergyData = {
let newList = []
coutriesEnergyRawData.forEach((obj) => {
newList.push({
"Country": obj.country,
"Year": obj.Year,
"Region": obj.Region,
"Total energy consumption (Mtoe)": obj["Total energy consumption (Mtoe)"]
})
})

return newList
}
Insert cell
allCountry = {
let newList = []
coutriesEnergyRawData.forEach((obj) => {
newList.push(obj.country)
})

return new Array(... new Set(newList))
}
Insert cell
coutriesGDPRawData = FileAttachment("Countries GDP 1960-2020.csv").csv({typed:true})
Insert cell
allCountryGDP = {
let newList = []
coutriesGDPRawData.forEach((obj) => {
newList.push(obj["Country Name"])
})

return new Array(... new Set(newList))
}
Insert cell
countriesInGDPandEnergy = {
let count = []
allCountry.forEach((country) => {
if (allCountryGDP.includes(country)) {
count.push(country)
}
})
return count;
}
Insert cell
delyears = {
let startyear = 1960
let endyear = 1990
let newlist = []
while (startyear < endyear){
newlist.push(startyear)
startyear++
}
return newlist
}
Insert cell
Insert cell
Insert cell
countriesNeedGDPEnergyList = {
let newlist = []
countriesGDPNeeded.forEach((obj1) => {
countriesInGDPandEnergyList.forEach((obj2) => {
if(obj1["Country Name"] == obj2["Country"]) {
for (let key in obj1) {
if (parseInt(key) == obj2["Year"]) {
newlist.push({
... obj2,
"GDP": obj1[key]
})
}
}
}
})
})
return newlist
}
Insert cell
populationRawData = FileAttachment("pop.csv").csv({typed:true})
Insert cell
needPopulationData = {
let newList = []
populationRawData.forEach((obj) => {
if (countriesInGDPandEnergy.includes(obj["country"])) {
newList.push(obj)
}
if(obj["country"] == "USA") {
newList.push({
... obj,
"country": "United States"
})
}
if(obj["country"] == "UK") {
newList.push({
... obj,
"country": "United Kingdom"
})
}
})
return newList.sort()
}
Insert cell
Insert cell
Insert cell
cleanPop = FileAttachment("cleaned_pop.csv").csv({typed:true})
Insert cell
data = {
let newlist = []
cleanPop.forEach((obj1) => {
countriesNeedGDPEnergyList.forEach((obj2) => {
if(obj1["Country"] == obj2["Country"]) {
for (let key in obj1) {
if (parseInt(key) == obj2["Year"]) {
newlist.push({
... obj2,
"Population": obj1[key]
})
}
}
}
})
})
return newlist
}
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