Expand description
Column statistics (#261): count, nulls, distinct values, min, max, mean, median, quantiles and the most common values, per column.
A column is numeric when every non-null cell is a number, or text that
parses as one (infer::parse_float); its
min and max are numeric, and it gets a mean, a median and quantiles
(linear interpolation between closest ranks, as NumPy’s default). Any
other column’s min and max compare the cells’ text. Nulls are
Value::Null and empty text; run Inference::apply first for other
null tokens.
Stats renders as a table, a row per column; Stats::headers gives
a short summary to show under each column heading instead.
use rich_data::stats::Stats;
use rich_data::{Rows, Value};
let mut rows = Rows::new(["service", "p99"]);
for (service, p99) in [("web", 120), ("api", 35), ("web", 80), ("db", 5)] {
rows.push([service.into(), Value::Int(p99)]);
}
let stats = Stats::of(&rows);
let p99 = &stats.columns()[1];
assert_eq!((p99.count, p99.nulls, p99.distinct), (4, 0, 4));
assert_eq!(p99.mean, Some(60.0));
assert_eq!(p99.median, Some(57.5));
let service = &stats.columns()[0];
assert_eq!(service.top[0], ("web".to_string(), 2));
assert_eq!(service.min.as_deref(), Some("api"));Structs§
- Column
Stats - One column’s statistics.
- Stats
- Statistics for every column. See the module docs.
- Stats
Options - What
Statscomputes beyond the counts.
Functions§
- number
- A number for display: whole numbers without a point, others to at most four decimals, and very small ones in scientific notation.