Statistics and classification¶
Two thin functions on top of a long-format result frame: named quantiles next to the extremes, and a class column that turns a continuous quantity into the bands a study argues in.
There is deliberately no built-in table of admissible values. Touch-voltage
limits depend on the clearing time, the standard edition and the additional
resistances assumed; a plausible-looking constant baked in here would be carried
into a result without ever being checked. classify takes its edges from the
caller, who can cite them.
statistics ¶
Summarise and classify a long-format result frame.
A parameter study produces hundreds of rows; a report needs a handful of numbers and a verdict. Polars already does the arithmetic, so these two functions add only the shape an engineering summary wants -- named quantiles next to the extremes, and a class column that turns a continuous quantity into the bands a study argues in.
Deliberately absent: any built-in table of admissible values. Touch-voltage
limits depend on the clearing time, the standard edition and the additional
resistances assumed, and a plausible-looking constant baked in here would be
carried into a result without ever being checked. :func:classify therefore
takes the edges from the caller, who can cite them.
summarize ¶
summarize(
frame: pl.DataFrame,
value: str,
*,
by: Optional[Sequence[str]] = None,
quantiles: Sequence[float] = DEFAULT_QUANTILES
) -> pl.DataFrame
Reduce one column to count, spread, quantiles and extremes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame
|
Long-format results, e.g. from
:meth: |
required |
value
|
str
|
Numeric column to summarise. |
required |
by
|
sequence of str
|
Grouping columns. Without them the whole frame is one group. |
None
|
quantiles
|
sequence of float
|
Quantiles in |
DEFAULT_QUANTILES
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per group: the grouping columns, then |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a named column is missing, if the value column is not numeric, or if
a quantile lies outside |
Examples:
Source code in src/groundinsight/analysis/statistics.py
classify ¶
classify(
frame: pl.DataFrame,
value: str,
edges: Sequence[float],
*,
labels: Optional[Sequence[str]] = None,
name: str = "class"
) -> pl.DataFrame
Add a class column by binning a numeric column at the given edges.
edges are the interior boundaries: n edges make n + 1 classes.
Bins are closed on the right, so a value exactly on an edge falls into the
lower class -- the conservative reading when the edge is a limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
DataFrame
|
Frame to extend. |
required |
value
|
str
|
Numeric column to classify. |
required |
edges
|
sequence of float
|
Strictly increasing interior boundaries, e.g. |
required |
labels
|
sequence of str
|
Names for the classes, |
None
|
name
|
str
|
Name of the added column. Defaults to |
'class'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The input with one column added. Rows whose value is null get a null class rather than being forced into the lowest band. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the column is missing or not numeric, if |
Examples:
Source code in src/groundinsight/analysis/statistics.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |