Published
Edited
May 9, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
df = await dfd
.readCSV(url)
.then((d) => d.setIndex({ column: "geography" }))
.then((de) => {
var mappings = {};

var cols = de.columns.filter((d) => d.includes(":"));

cols.forEach((d, i) => {
// de = de.asType(d, "int32");
// if (i === 0) {
// mappings[d] = "totals";
// } else {
mappings[d] = /:(.+);/.exec(d)[1];
// }
});

return de
.loc({ rows: de.index.filter((d) => d), columns: cols })
.rename(mappings, { inplace: false });
})
Insert cell
df.$columns
Insert cell
Insert cell
Insert cell
no_sub = {
var cols = df.$columns.filter(
(d) => !(d.includes("count") || d.includes("All usual"))
); //d.includes(":") ||
return df.loc({ columns: cols });
}
Insert cell
percentages = no_sub.div(no_sub.sum(), { axis: 0 })
Insert cell
dfd.toJSON(percentages, { format: "row" })
Insert cell
percentages.$data
Insert cell
6) View Tables
Insert cell
html`<div id='table' style='height:500px;width:100%;display:block'></div>`
Insert cell
Insert cell
7) Sanity Plot
Insert cell
html`<div id='plot_div' style='height:600px;display:block'></div>`
Insert cell
percentages.plot("plot_div").bar()
Insert cell
df
Insert cell
Insert cell
Insert cell
// viewof search = Inputs.search(data)
Insert cell
// Inputs.table(search, {
// format: {
// Year: d3.format("d") // format as "1960" rather than "1,960"
// }
// })
Insert cell
dfd = require("https://cdn.jsdelivr.net/npm/danfojs@1.1.0/lib/bundle.min.js").catch(
() => {
window.dfd.Series.prototype.print = window.dfd.DataFrame.prototype.print = function () {
return print(this);
};
return window.dfd;
}
)
Insert cell
html`
<style>
p{
color:steelblue;

}
</style>`
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