staircase.StairsSlicer.resample¶
- StairsSlicer.resample(func)¶
Creates a new step function by applying a function to the step function slices, and replacing the slices with the new values.
- Parameters
- func{“min”, “max”, “mean”, “median”, “mode”, “integral”}
The function applied to the step function slices.
- Returns
staircase.Stairs
Examples
>>> df = sc.make_test_data(seed=0) >>> sf = sc.Stairs(df, "start", "end", "value") >>> sf.plot()
>>> cuts = pd.date_range("2021", "2022", freq="MS") >>> ax = sf.slice(cuts).resample("mean").plot() >>> ax.xaxis.set_major_formatter(DateFormatter('%b-%y')) >>> ax.set_title("resampled by mean")
>>> s = sc.Stairs( ... start=[1, -4, 3, 6, 7], ... end=[10, 5, 5, 7, 10], ... value=[2, -1.75, 2.5, -2.5, -2.5] ... ) >>> cuts = [0,2,4,6] >>> resampled = s.slice(cuts).resample("mean") >>> fig, axes = plt.subplots(ncols=2, figsize=(7,3), sharex=True, sharey=True) >>> for ax in axes: ... for x in cuts: ... ax.axvline(x, c="r", linestyle="--", alpha=0.3) >>> s.plot(axes[0]) >>> axes[0].set_title("s") >>> resampled.plot(axes[1]) >>> axes[1].set_title("s resampled by mean")