Public
Edited
Oct 24, 2023
1 fork
7 stars
Insert cell
Insert cell
Insert cell
bad = d3.csvParse(text)
Insert cell
Inputs.table(bad, {width: 550})
Insert cell
Insert cell
rows = d3.csvParseRows(text)
Insert cell
Inputs.table(rows, {width: 550})
Insert cell
Insert cell
better = csvParseDuplicate(text)
Insert cell
Inputs.table(better, {width: 550})
Insert cell
function csvParseDuplicate(text, {empty = "_default", dedup = (name, j) => `${name}~${j}`} = {}) {
const columns = [];
return Object.assign(d3.csvParseRows(text, (row, i) => {
if (i === 0) {
for (let name of row) {
let n = name || (name = empty);
let j = 0;
while (columns.includes(n)) n = dedup(name, ++j);
columns.push(n);
}
return;
}
return Object.fromEntries(columns.map((c, i) => [c, row[i]]));
}), {columns});
}
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