zabgrab.services.binning¶
Counting values in bins (show --bin and plot --bin).
Bins are given by their edges, in increasing order. N edges make N + 1 bins: the
first holds everything below the first edge and the last everything from the last
edge up, and each bin includes its lower edge but not its upper one, as
numpy.histogram’s bins do: with edges 10 and 100, 10 is in 10 to 100 and
100 in ≥ 100.
Functions
|
Count each numeric series' values in bins. |
Classes
|
Bins, by their edges. |
|
How many of a series' values fall in each bin. |
- class zabgrab.services.binning.Bins(edges)[source]¶
Bases:
objectBins, by their edges.
Examples
>>> bins = Bins.parse(["10,100", "1000"]) >>> bins.labels ['< 10', '10 to 100', '100 to 1000', '≥ 1000'] >>> [bins.index(value) for value in (5, 10, 99.9, 100, 5000)] [0, 1, 1, 2, 3]
- classmethod parse(texts)[source]¶
Read bin edges given on the command line.
- Parameters:
texts (sequence of str) – Comma-separated numbers; each
--bingiven adds its edges.- Returns:
Bins – The bins.
- Raises:
ValueError – If an edge isn’t a finite number, or the edges aren’t increasing.
- Return type:
- position(value)[source]¶
Place a value along the bins, drawn side by side one unit apart.
Bin
iis centred oni, so the edge between binsiandi + 1is ati + 0.5. A value inside a bin between two edges is placed in proportion between them. The first and last bins are open-ended, with no width to measure against, so values inside them go in their middle.- Parameters:
value (float) – The value.
- Returns:
position (float) – Where the value goes.
exact (bool) – Whether the position is exact (
Falseinside an open-ended bin).
- Return type:
Examples
>>> bins = Bins((10, 100, 1000)) >>> [bins.position(value) for value in (10, 55, 1000, 5, 5000)] [(0.5, True), (1.0, True), (2.5, True), (0, False), (3, False)]
- class zabgrab.services.binning.Histogram(series, counts)[source]¶
Bases:
objectHow many of a series’ values fall in each bin.
- zabgrab.services.binning.histograms(series, bins, options=None)[source]¶
Count each numeric series’ values in bins.
Raw data’s values are counted, and hourly trends’ averages. Text items have no size, so they’re left out.
- Parameters:
series (sequence of Series) – The data.
bins (Bins) – The bins.
options (ListingOptions, optional) – Filters to apply first (
--grep,--aboveand--below).
- Returns:
list of Histogram – One per numeric series, in the order given.
- Return type: