Published
Edited
Jul 16, 2020
1 fork
44 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
kw = require('https://bundle.run/kiwis@0.0.7')
Insert cell
Insert cell
Insert cell
h2g2Characters = kw.DataFrame([
{
name: 'Marvin',
surname: '',
occupation: 'Paranoid Android'
},
{
name: 'Zaphod',
surname: 'Beeblebrox',
occupation: 'President of the Galaxy'
},
{
name: 'Arthur',
surname: 'Dent',
occupation: null
}
])
Insert cell
Insert cell
h2g2Characters.toString()
Insert cell
Insert cell
h2g2Characters.columns
Insert cell
h2g2Characters.length
Insert cell
Insert cell
h2g2Characters.get(1)
Insert cell
h2g2Characters.first()
Insert cell
h2g2Characters.last()
Insert cell
Insert cell
h2g2Characters.name.toString()
Insert cell
Insert cell
h2g2Characters.toArray()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
oscars = kw.parseCSV(await FileAttachment('oscar_results@1.csv').text(), { prettify: 'camelCase' })
Insert cell
oscars.toString()
Insert cell
Insert cell
// Get the min and max values for the year
oscars.year.extent()
Insert cell
// Get the average box office
oscars.boxOffice.mean()
Insert cell
// Get the different categories
oscars.category.unique()
Insert cell
// Get the 20 movies with the most nominations ("A Star Is Born" is cheating cause there are two of them!)
oscars.title.counts().slice(0, 20)
Insert cell
// Get the 20 movies with the most wins
oscars.filter(row => row.winner === 'true').title.counts().slice(0, 20)
Insert cell
// Only show Sci-Fi movies that won an Oscar
oscars.filter(row => row.genres.includes('Sci-Fi') && row.winner === 'true').toString()
Insert cell
// Only show movies that won Best Picture and were the biggest commercial success of the year (1st at the box office)
oscars.filter(row => row.category === 'Best Picture' && row.winner === 'true' && row.rank === 1).toString()
Insert cell
// Exclude 'Best Visual Effects' from the dataset and only keep a subset of the columns, renaming and reordering them
oscars
.drop(row => row.category === 'Best Visual Effects')
.filter(['year', 'title', 'category', 'winner'])
.rename({ title: 'name', category: 'award' })
.reorder(['name', 'year', 'award', 'winner'])
.toString()
Insert cell
Insert cell
oscars.sort(['year', 'boxOffice']).toString()
Insert cell
Insert cell
pivotTable = oscars.pivot(['category', 'year'])
Insert cell
JSON.parse(pivotTable.toJSON())
Insert cell
// Show the number of films nominated for each category and ceremony
pivotTable.count().toString()
Insert cell
// Show the average box office of the nominees for each category and ceremony
pivotTable.mean('boxOffice').toString()
Insert cell
// Show the winner for each category and ceremony, but remove the rows where the winner is missing
pivotTable
.rollup(l => {
const winner = l.find(row => row.winner === 'true');
return winner ? winner.title : null;
}, { name: 'winner' })
.dropNA()
.toString()
Insert cell
Insert cell
Insert cell
Insert cell
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