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

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