cutBinsToFrame

cutBinsToFrame(result, { data }) converts the output of cut() or qcut() into a summary DataFrame with one row per bin, showing the bin label, edges, count, and frequency.

Interactive Demo

Click "Run" to see the result.

What it does

import { cut, cutBinsToFrame, cutBinCounts, binEdges } from "tsb";

// Bin 20 random values into 4 equal-width bins
const data = Array.from({ length: 20 }, () => Math.random() * 100);
const result = cut(data, 4);

// Summary DataFrame: bin | left | right | count | frequency
const df = cutBinsToFrame(result, { data });

// Just the count dictionary
const counts = cutBinCounts(result);
// { "(0.0, 25.0]": 5, "(25.0, 50.0]": 6, ... }

// Just edges indexed by label
const edges = binEdges(result);

Related Functions