Published
Edited
Insert cell
Insert cell
Insert cell
arrow = require('@apache-arrow/es5-umd@0.15.1')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
LENGTH = 2000
Insert cell
rainAmounts = Float32Array.from({length: LENGTH}, () => Number((Math.random() * 20).toFixed(1)))
Insert cell
rainDates = Array.from({length: LENGTH}, (_, i) => Date.now() - 1000 * 60 * 60 * 24 * i)
Insert cell
rainfall = arrow.Table.new(
[arrow.FloatVector.from(rainAmounts), arrow.DateVector.from(rainDates)],
['precipitation', 'date']
);
Insert cell
Insert cell
rainfall.length
Insert cell
rainfall.get(10).toString()
Insert cell
rainfall.getColumn('date').toArray().slice(3,6)
Insert cell
rainfall.toString().slice(0,200)
Insert cell
Insert cell
rainfall.count()
Insert cell
weather = ({
sunny: rainfall.filter( arrow.predicate.col('precipitation').eq(0) ) .count(),
flooding: rainfall.filter( arrow.predicate.col('precipitation').gt(18) ) .count(),
misty: rainfall
.filter(
arrow.predicate.col('precipitation').gt(0)
.and( arrow.predicate.col('precipitation').lt(1) )) .count()
})
Insert cell
Insert cell
weather2 = ({
thisWeek: rainfall
.filter(arrow.predicate.custom(idx => idx < 7, () => 1)).count(),
niceThisWeek: rainfall
.filter(arrow.predicate.custom(idx => idx < 7, () => 1))
.filter(arrow.predicate.col('precipitation').lt(0.3)).count()
})
Insert cell
Insert cell
hours = (function () {
const arr = [];
for (const x of rainfall.getColumn('date')) {
arr.push(x.getHours())
}
return arr;
}())
Insert cell
Insert cell
//highest rainfall
(function () {
const vec = rainfall.getColumn('precipitation')
let highIdx = 0;
rainfall.scan((idx) => { highIdx = vec.get(idx) > vec.get(highIdx) ? idx : highIdx; } )
return {
idx: highIdx,
str: rainfall.get(highIdx).toString()
};
}())
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