Published
Edited
Jul 15, 2021
1 star
Insert cell
md`# Summer Olympics medals by country`
Insert cell
FileAttachment("Summer-Olympic-medals-1976-to-2008.csv").csv()
Insert cell
OlympicsFile = FileAttachment("Summer-Olympic-medals-1976-to-2008.csv")
Insert cell
d3 = require("d3@6")
Insert cell
arrOfCountryCodesAndMedals = d3.csvParse(await FileAttachment("Summer-Olympic-medals-1976-to-2008.csv").text(), function(data) {
return {
Country_Code : data.Country_Code,
Medal : data.Medal,
};
})
Insert cell
usaArr = []
Insert cell
arrOfCountryCodesAndMedals.forEach((i) => {
if(i.Country_Code == "USA") {
console.log(`USA ${i}`);
usaArr.push(i);
}
});

Insert cell
usaArr
Insert cell
usaArr.length //number of medals USA has won in Summer Olympics between 1976 and 2008
Insert cell
countrycodes = [] //rerun this cell when following cell is edited
Insert cell
arrOfCountryCodesAndMedals.forEach((cc) => {
if (countrycodes.indexOf(cc.Country_Code) < 0 && cc.Country_Code.length > 0) {
countrycodes.push(cc.Country_Code);
}
});
Insert cell
countrycodes //just the country codes
Insert cell
map = new Object()
Insert cell
arrOfCountryCodesAndMedals.forEach((i)=> {
if(!map.hasOwnProperty(i.Country_Code)){map[i.Country_Code] = {gold:0,silver:0,bronze:0};}
if(i.Medal === "Gold") {
map[i.Country_Code].gold++;
}
else if(i.Medal === "Silver") {
map[i.Country_Code].silver++;
}
else if(i.Medal === "Bronze") {
map[i.Country_Code].bronze++;
}
})
Insert cell
map
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more