Danfo.js: show missing values before publishing a table

Keep unavailable readings visible beside the sum of supplied values.

A table cell is blank, but the report never says whether that means zero or an unavailable reading. Count missing values before calculating the report, and keep the count next to the data. Filling every gap with zero would answer a different question.

Take a fictional three-row inspection extract: A has six readings, B has an unavailable reading, and C has four. There are three source rows, two supplied numeric readings, and one missing reading. The known values sum to ten. Do not label ten as a complete total for all three inspections unless the source owner has supplied the missing value or an explicit rule for it.

Danfo DataFrame: column missing counts and a deliberate zero comparison
Danfo DataFrame: column missing counts and a deliberate zero comparison
Open the full example ↗

Open the complete example · Download the full HTML source

Inspect the DataFrame before choosing a policy

The official Danfo.js README documents browser use of its dfd namespace and demonstrates isNa().sum() for reporting missing values. It also distinguishes the browser package from the Node package. Use the browser distribution for an HTML page; copying a server-side import does not establish a working browser build.

const frame = new dfd.DataFrame({
  inspection: ['A', 'B', 'C'],
  readings: [6, NaN, 4]
});
const missingByColumn = frame.isNa().sum({axis: 0});
const missingCounts = missingByColumn.values;

Here NaN is deliberately supplied to represent the exercise's unavailable numeric reading. Pass axis: 0 to reduce down the rows and obtain one count per column. Pair the returned counts with the corresponding column labels when rendering them. Inspect the result for the chosen package release rather than assuming that an unlabeled position means the readings column.

Preserve the difference between missing and zero

Show a readable label such as “Not supplied” for B while retaining the missing representation in the analysis data. Use zero only when zero was supplied or the agreed transformation explicitly requires it. In a second fixture, replace B's missing reading with a real zero: the source then has three supplied numeric readings and no missing reading, although its numeric sum is still ten.

Those two ten-unit results have different coverage. Displaying only the sum conceals that distinction. A useful reading surface lists source rows, supplied readings, missing readings, and the sum of supplied values with a label that states its scope.

The existing Papa Parse CSV review rejects an absent mandatory quantity before presenting a successful total. This task is different: it describes an analysis extract in which unavailable readings remain visible. Decide whether a missing field is permitted before selecting either behavior.

When you turn the accepted extract into a reading copy, the HTML table from CSV guide covers table markup and a separate source-file download. Keep the missing-value labels and coverage counts beside that table so its presentation does not hide the analysis policy.

Write the transformation rule in plain language

For this exercise, use: “Keep every source row. Do not replace missing readings. Sum supplied numeric readings only, and disclose how many readings are missing.” That statement is short enough to sit above the result and precise enough for a reviewer to disagree with.

If your real task instead excludes incomplete rows, report the excluded count and the reason. If it imputes a value, show the method and identify which cells changed. Neither decision should be hidden inside a display helper. Keep the original extract so the transformation can be checked against it.

Before handing over the HTML, try the original missing fixture, the zero fixture, and a fully supplied replacement for B. Clear the previous summary when the source changes. Compare the displayed missing count with the source rows independently, then ask the data owner to approve the policy rather than merely approving the appearance of the table.

Keep reading