cut_after

trashpanda.cut_after(source_to_cut: pandas.core.series.Series, cutting_index: float) pandas.core.series.Series
trashpanda.cut_after(source_to_cut: pandas.core.frame.DataFrame, cutting_index: float) pandas.core.frame.DataFrame

Cuts a dataframe dropping the part after the cutting index. The cutting index will be added to the frame, which values are being interpolated, if inside.

Parameters
  • source_to_cut (Union[Series, DataFrame]) – Source frame to be cut at the cutting index.

  • cutting_index (float) – Cutting index at which the source frame should be cut.

Returns

Union[Series, DataFrame]

Examples

Usage with pandas.Series

>>> import numpy
>>> from pandas import Series, Index
>>> from doctestprinter import doctest_print
>>> from trashpanda import cut_after
>>> sample_series = Series(
...     numpy.arange(3.0),
...     index=Index([0.1, 0.2, 0.3], name="x"),
...     name="y"
... )
>>> sample_series
x
0.1    0.0
0.2    1.0
0.3    2.0
Name: y, dtype: float64
>>> cut_after(sample_series, 0.1)
x
0.1    0.0
Name: y, dtype: float64
>>> cut_after(sample_series, 0.14)
x
0.10    0.0
0.14    0.4
Name: y, dtype: float64
>>> cut_after(sample_series, 0.2)
x
0.1    0.0
0.2    1.0
Name: y, dtype: float64
>>> cut_after(sample_series, 0.31)
x
0.10    0.0
0.20    1.0
0.30    2.0
0.31    NaN
Name: y, dtype: float64
>>> cut_after(sample_series, 0.0)
Series([], Name: y, dtype: float64)

Usage with a pandas.DataFrame

>>> import numpy
>>> from pandas import DataFrame, Index
>>> from doctestprinter import doctest_print
>>> from trashpanda import cut_after
>>> sample_frame = DataFrame(
...     numpy.arange(6.0).reshape(3, 2),
...     columns=["b", "a"],
...     index=Index([0.1, 0.2, 0.3], name="x")
... )
>>> doctest_print(sample_frame)
       b    a
x
0.1  0.0  1.0
0.2  2.0  3.0
0.3  4.0  5.0
>>> doctest_print(cut_after(sample_frame, 0.1))
       b    a
x
0.1  0.0  1.0
>>> doctest_print(cut_after(sample_frame, 0.14))
        b    a
x
0.10  0.0  1.0
0.14  0.8  1.8
>>> doctest_print(cut_after(sample_frame, 0.2))
       b    a
x
0.1  0.0  1.0
0.2  2.0  3.0
>>> doctest_print(cut_after(sample_frame, 0.31))
        b    a
x
0.10  0.0  1.0
0.20  2.0  3.0
0.30  4.0  5.0
0.31  NaN  NaN
>>> cut_after(sample_frame, 0.0)
Empty DataFrame
Columns: [b, a]
Index: []