Public
Edited
Jul 23, 2024
Insert cell
Insert cell
printTable(flights.slice(0, 5)) // display the first five rows
Insert cell
data['flights-10k.json'].url
Insert cell
Insert cell
Insert cell
flights.filter(flight => flight.delay < 0).sort((a, b) => a.delay - b.delay)
Insert cell
new Set(flights.map(f => f.origin))
Insert cell
Insert cell
_.orderBy(flights.filter(flight => flight.origin === 'SJC' || flight.destination === 'SJC'),
['origin', 'destination'], ['asc', 'desc'])
Insert cell
Insert cell
{
const regexp = /DAL|HOU/; // new RegExp('DAL|HOU')

return flights.filter(flight => flight.origin.match(regexp))
}
Insert cell
{
const airports = ['DAL', 'HOU'];

return flights.filter(flight => airports.indexOf(flight.origin) !== -1);
}
Insert cell
Insert cell
d3.extent(flights.map(f => f.date))
Insert cell
flights
.filter((flight) => flight.date >= new Date("2001-03-01"))
.sort((a, b) => a.date - b.date)
Insert cell
Insert cell
flights
.filter(
(flight) =>
flight.date >= new Date("2001-01-01") &&
flight.date < new Date("2001-02-01")
)
.sort((a, b) => a.date - b.date)
Insert cell
Insert cell
Insert cell
{
const keepCols = ['origin', 'destination'];

const selectedData = flights.map(obj => {
let tmpObj = {};
selectColsByName(tmpObj, obj, keepCols);
return tmpObj;
});

return selectedData
}
Insert cell
Insert cell
Insert cell
{
const keepCols = /de/;

const selectedData = flights.map(obj => {
let tmpObj = {};
selectColsByRegExp(tmpObj, obj, new RegExp(keepCols));
return tmpObj;
});

return selectedData;
}
Insert cell
Insert cell
Insert cell
flights = (await data['flights-10k.json']()).map(f => ({ ...f, date: new Date(f.date) }))
Insert cell
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