Published
Edited
Nov 13, 2019
2 forks
23 stars
Insert cell
Insert cell
Insert cell
arrow = require('@apache-arrow/es5-umd@0.15.1')
Insert cell
Insert cell
fields = [
{
name: 'precipitation',
type: { name: 'floatingpoint', precision: 'SINGLE'},
nullable: false, children: []
},
{
name: 'date',
type: { name: 'date', unit: 'MILLISECOND' },
nullable: false, children: []
}
]
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(20).toString()
Insert cell
rainfall.getColumn('date').toArray().slice(3,6)
Insert cell
rainfall.toArray().slice(1,4).join(', ')
Insert cell
rainfall.serialize()
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; } )
const row = rainfall.get(highIdx)
return `${row.date} => ${row.precipitation} inches`
}())
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