Published
Edited
Nov 11, 2019
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

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