staircase.StairsSlicer.hist¶
- StairsSlicer.hist(*args, **kwargs)¶
Calculates histogram data for each of the step function slices
- Parameters
- bins“unit”, sequence or
pandas.IntervalIndex
If bins is “unit” then the histogram bins will have unit length and cover the range of step function values. If bins is a sequence, it defines a monotonically increasing array of bin edges. If bins are defined by
pandas.IntervalIndex
they should be non-overlapping and monotonic increasing.- closed{“left”, “right”}, default “left”
Indicates whether the histogram bins are left-closed right-open or right-closed left-open. Only relevant when bins is not a
pandas.IntervalIndex
- stat{“sum”, “frequency”, “density”, “probability”}, default “sum”
- The aggregate statistic to compute in each bin. Inspired by
seaborn.histplot()
stat parameter. sum
the magnitude of observationsfrequency
values of the histogram are divided by the corresponding bin widthdensity
normalises values of the histogram so that the area is 1probability
normalises values so that the histogram values sum to 1
- The aggregate statistic to compute in each bin. Inspired by
- bins“unit”, sequence or
- Returns
pandas.Dataframe
Each row corresponds to a step function slice. Each column corresponds to a bin.
Examples
>>> df = sc.make_test_data(seed=0) >>> sf = sc.Stairs(df, "start", "end", "value") >>> sf.plot()
>>> cuts = pd.date_range("2021", periods=12, freq="MS") >>> sf.slice(cuts).hist(bins=[300, 400, 500, 600], stat="probability") [300.0, 400.0) [400.0, 500.0) [500.0, 600.0) [2021-01-01, 2021-02-01) 0.216756 0.783244 0.000000 [2021-02-01, 2021-03-01) 0.927480 0.072520 0.000000 [2021-03-01, 2021-04-01) 0.000000 0.443907 0.556093 [2021-04-01, 2021-05-01) 0.000000 0.487269 0.512731 [2021-05-01, 2021-06-01) 0.618996 0.381004 0.000000 [2021-06-01, 2021-07-01) 0.592523 0.407477 0.000000 [2021-07-01, 2021-08-01) 0.000000 0.684812 0.315188 [2021-08-01, 2021-09-01) 0.000000 0.985954 0.014046 [2021-09-01, 2021-10-01) 0.029444 0.970556 0.000000 [2021-10-01, 2021-11-01) 0.000000 0.992876 0.007124 [2021-11-01, 2021-12-01) 0.000000 0.875370 0.124630