Skip to content

accessors module

Custom pandas accessors for generic data.

Methods can be accessed as follows:

>>> import pandas as pd
>>> import vectorbt as vbt

>>> # vectorbt.generic.accessors.GenericAccessor.rolling_mean
>>> pd.Series([1, 2, 3, 4]).vbt.rolling_mean(2)
0    NaN
1    1.5
2    2.5
3    3.5
dtype: float64

The accessors inherit vectorbt.base.accessors and are inherited by more specialized accessors, such as vectorbt.signals.accessors and vectorbt.returns.accessors.

Note

Grouping is only supported by the methods that accept the group_by argument.

Accessors do not utilize caching.

Run for the examples below

>>> import vectorbt as vbt
>>> import numpy as np
>>> import pandas as pd
>>> from numba import njit
>>> from datetime import datetime, timedelta

>>> df = pd.DataFrame({
...     'a': [1, 2, 3, 4, 5],
...     'b': [5, 4, 3, 2, 1],
...     'c': [1, 2, 3, 2, 1]
... }, index=pd.Index([
...     datetime(2020, 1, 1),
...     datetime(2020, 1, 2),
...     datetime(2020, 1, 3),
...     datetime(2020, 1, 4),
...     datetime(2020, 1, 5)
... ]))
>>> df
            a  b  c
2020-01-01  1  5  1
2020-01-02  2  4  2
2020-01-03  3  3  3
2020-01-04  4  2  2
2020-01-05  5  1  1

>>> index = [datetime(2020, 1, 1) + timedelta(days=i) for i in range(10)]
>>> sr = pd.Series(np.arange(len(index)), index=index)
>>> sr
2020-01-01    0
2020-01-02    1
2020-01-03    2
2020-01-04    3
2020-01-05    4
2020-01-06    5
2020-01-07    6
2020-01-08    7
2020-01-09    8
2020-01-10    9
dtype: int64

Stats

>>> df2 = pd.DataFrame({
...     'a': [np.nan, 2, 3],
...     'b': [4, np.nan, 5],
...     'c': [6, 7, np.nan]
... }, index=['x', 'y', 'z'])

>>> df2.vbt(freq='d').stats(column='a')
Start                      x
End                        z
Period       3 days 00:00:00
Count                      2
Mean                     2.5
Std                 0.707107
Min                      2.0
Median                   2.5
Max                      3.0
Min Index                  y
Max Index                  z
Name: a, dtype: object

Mapping

Mapping can be set both in GenericAccessor (preferred) and StatsBuilderMixin.stats():

>>> mapping = {x: 'test_' + str(x) for x in pd.unique(df2.values.flatten())}
>>> df2.vbt(freq='d', mapping=mapping).stats(column='a')
Start                                   x
End                                     z
Period                    3 days 00:00:00
Count                                   2
Value Counts: test_2.0                  1
Value Counts: test_3.0                  1
Value Counts: test_4.0                  0
Value Counts: test_5.0                  0
Value Counts: test_6.0                  0
Value Counts: test_7.0                  0
Value Counts: test_nan                  1
Name: a, dtype: object

>>> df2.vbt(freq='d').stats(column='a', settings=dict(mapping=mapping))
UserWarning: Changing the mapping will create a copy of this object.
Consider setting it upon object creation to re-use existing cache.

Start                                   x
End                                     z
Period                    3 days 00:00:00
Count                                   2
Value Counts: test_2.0                  1
Value Counts: test_3.0                  1
Value Counts: test_4.0                  0
Value Counts: test_5.0                  0
Value Counts: test_6.0                  0
Value Counts: test_7.0                  0
Value Counts: test_nan                  1
Name: a, dtype: object

Selecting a column before calling stats will consider uniques from this column only:

>>> df2['a'].vbt(freq='d', mapping=mapping).stats()
Start                                   x
End                                     z
Period                    3 days 00:00:00
Count                                   2
Value Counts: test_2.0                  1
Value Counts: test_3.0                  1
Value Counts: test_nan                  1
Name: a, dtype: object

To include all keys from mapping, pass incl_all_keys=True:

df2['a'].vbt(freq='d', mapping=mapping).stats(settings=dict(incl_all_keys=True)) Start x End z Period 3 days 00:00:00 Count 2 Value Counts: test_2.0 1 Value Counts: test_3.0 1 Value Counts: test_4.0 0 Value Counts: test_5.0 0 Value Counts: test_6.0 0 Value Counts: test_7.0 0 Value Counts: test_nan 1 Name: a, dtype: object

`GenericAccessor.stats` also supports (re-)grouping:

```pycon
>>> df2.vbt(freq='d').stats(column=0, group_by=[0, 0, 1])
Start                      x
End                        z
Period       3 days 00:00:00
Count                      4
Mean                     3.5
Std                 1.290994
Min                      2.0
Median                   3.5
Max                      5.0
Min Index                  y
Max Index                  z
Name: 0, dtype: object

Plots

GenericAccessor class has a single subplot based on GenericAccessor.plot():

>>> df2.vbt.plots()


nb_config Config

Config of Numba methods to be added to GenericAccessor.

Config({
    "shuffle": {
        "func": "CPUDispatcher(<function shuffle_nb at 0x11847c680>)",
        "path": "vectorbt.generic.nb.shuffle_nb"
    },
    "fillna": {
        "func": "CPUDispatcher(<function fillna_nb at 0x11847e020>)",
        "path": "vectorbt.generic.nb.fillna_nb"
    },
    "bshift": {
        "func": "CPUDispatcher(<function bshift_nb at 0x118473ba0>)",
        "path": "vectorbt.generic.nb.bshift_nb"
    },
    "fshift": {
        "func": "CPUDispatcher(<function fshift_nb at 0x11847c0e0>)",
        "path": "vectorbt.generic.nb.fshift_nb"
    },
    "diff": {
        "func": "CPUDispatcher(<function diff_nb at 0x11847ea20>)",
        "path": "vectorbt.generic.nb.diff_nb"
    },
    "pct_change": {
        "func": "CPUDispatcher(<function pct_change_nb at 0x11847f060>)",
        "path": "vectorbt.generic.nb.pct_change_nb"
    },
    "bfill": {
        "func": "CPUDispatcher(<function bfill_nb at 0x11847f6a0>)",
        "path": "vectorbt.generic.nb.bfill_nb"
    },
    "ffill": {
        "func": "CPUDispatcher(<function ffill_nb at 0x11847fce0>)",
        "path": "vectorbt.generic.nb.ffill_nb"
    },
    "cumsum": {
        "func": "CPUDispatcher(<function nancumsum_nb at 0x1184844a0>)",
        "path": "vectorbt.generic.nb.nancumsum_nb"
    },
    "cumprod": {
        "func": "CPUDispatcher(<function nancumprod_nb at 0x118484860>)",
        "path": "vectorbt.generic.nb.nancumprod_nb"
    },
    "rolling_min": {
        "func": "CPUDispatcher(<function rolling_min_nb at 0x118486840>)",
        "path": "vectorbt.generic.nb.rolling_min_nb"
    },
    "rolling_max": {
        "func": "CPUDispatcher(<function rolling_max_nb at 0x118486e80>)",
        "path": "vectorbt.generic.nb.rolling_max_nb"
    },
    "rolling_mean": {
        "func": "CPUDispatcher(<function rolling_mean_nb at 0x1184874c0>)",
        "path": "vectorbt.generic.nb.rolling_mean_nb"
    },
    "expanding_min": {
        "func": "CPUDispatcher(<function expanding_min_nb at 0x118498e00>)",
        "path": "vectorbt.generic.nb.expanding_min_nb"
    },
    "expanding_max": {
        "func": "CPUDispatcher(<function expanding_max_nb at 0x118499440>)",
        "path": "vectorbt.generic.nb.expanding_max_nb"
    },
    "expanding_mean": {
        "func": "CPUDispatcher(<function expanding_mean_nb at 0x1184998a0>)",
        "path": "vectorbt.generic.nb.expanding_mean_nb"
    },
    "product": {
        "func": "CPUDispatcher(<function nanprod_nb at 0x1184840e0>)",
        "is_reducing": true,
        "path": "vectorbt.generic.nb.nanprod_nb"
    }
})

transform_config Config

Config of transform methods to be added to GenericAccessor.

Config({
    "binarize": {
        "transformer": "<class 'sklearn.preprocessing._data.Binarizer'>",
        "docstring": "See `sklearn.preprocessing.Binarizer`."
    },
    "minmax_scale": {
        "transformer": "<class 'sklearn.preprocessing._data.MinMaxScaler'>",
        "docstring": "See `sklearn.preprocessing.MinMaxScaler`."
    },
    "maxabs_scale": {
        "transformer": "<class 'sklearn.preprocessing._data.MaxAbsScaler'>",
        "docstring": "See `sklearn.preprocessing.MaxAbsScaler`."
    },
    "normalize": {
        "transformer": "<class 'sklearn.preprocessing._data.Normalizer'>",
        "docstring": "See `sklearn.preprocessing.Normalizer`."
    },
    "robust_scale": {
        "transformer": "<class 'sklearn.preprocessing._data.RobustScaler'>",
        "docstring": "See `sklearn.preprocessing.RobustScaler`."
    },
    "scale": {
        "transformer": "<class 'sklearn.preprocessing._data.StandardScaler'>",
        "docstring": "See `sklearn.preprocessing.StandardScaler`."
    },
    "quantile_transform": {
        "transformer": "<class 'sklearn.preprocessing._data.QuantileTransformer'>",
        "docstring": "See `sklearn.preprocessing.QuantileTransformer`."
    },
    "power_transform": {
        "transformer": "<class 'sklearn.preprocessing._data.PowerTransformer'>",
        "docstring": "See `sklearn.preprocessing.PowerTransformer`."
    }
})

GenericAccessor class

GenericAccessor(
    obj,
    mapping=None,
    **kwargs
)

Accessor on top of data of any type. For both, Series and DataFrames.

Accessible through pd.Series.vbt and pd.DataFrame.vbt.

Superclasses

Inherited members

Subclasses


apply_along_axis method

GenericAccessor.apply_along_axis(
    apply_func_nb,
    *args,
    axis=0,
    wrap_kwargs=None
)

Apply a function apply_func_nb along an axis.


apply_and_reduce method

GenericAccessor.apply_and_reduce(
    apply_func_nb,
    reduce_func_nb,
    apply_args=None,
    reduce_args=None,
    wrap_kwargs=None
)

See apply_and_reduce_nb().

Usage

>>> greater_nb = njit(lambda col, a: a[a > 2])
>>> mean_nb = njit(lambda col, a: np.nanmean(a))
>>> df.vbt.apply_and_reduce(greater_nb, mean_nb)
a    4.0
b    4.0
c    3.0
dtype: float64

apply_mapping method

GenericAccessor.apply_mapping(
    **kwargs
)

See apply_mapping().


applymap method

GenericAccessor.applymap(
    apply_func_nb,
    *args,
    wrap_kwargs=None
)

See applymap_nb().

Usage

>>> multiply_nb = njit(lambda i, col, a: a ** 2)
>>> df.vbt.applymap(multiply_nb)
               a     b    c
2020-01-01   1.0  25.0  1.0
2020-01-02   4.0  16.0  4.0
2020-01-03   9.0   9.0  9.0
2020-01-04  16.0   4.0  4.0
2020-01-05  25.0   1.0  1.0

barplot method

GenericAccessor.barplot(
    trace_names=None,
    x_labels=None,
    return_fig=True,
    **kwargs
)

Create Bar and return the figure.

Usage

>>> df.vbt.barplot()


bfill method

GenericAccessor.bfill(
    *,
    wrap_kwargs=None
)

See bfill_nb().


binarize method

GenericAccessor.binarize(
    *,
    threshold=0.0,
    copy=True,
    **kwargs
)

See sklearn.preprocessing.Binarizer.


boxplot method

GenericAccessor.boxplot(
    trace_names=None,
    group_by=None,
    return_fig=True,
    **kwargs
)

Create Box and return the figure.

Usage

>>> df.vbt.boxplot()


bshift method

GenericAccessor.bshift(
    n=1,
    fill_value=nan,
    *,
    wrap_kwargs=None
)

See bshift_nb().


count method

GenericAccessor.count(
    group_by=None,
    wrap_kwargs=None
)

Return count of non-NaN elements.


crossed_above method

GenericAccessor.crossed_above(
    other,
    wait=0,
    broadcast_kwargs=None,
    wrap_kwargs=None
)

Generate crossover above another array.

See crossed_above_nb().

Usage

>>> df['b'].vbt.crossed_above(df['c'])
2020-01-01    False
2020-01-02    False
2020-01-03    False
2020-01-04    False
2020-01-05    False
dtype: bool
>>> df['a'].vbt.crossed_above(df['b'])
2020-01-01    False
2020-01-02    False
2020-01-03    False
2020-01-04     True
2020-01-05    False
dtype: bool
>>> df['a'].vbt.crossed_above(df['b'], wait=1)
2020-01-01    False
2020-01-02    False
2020-01-03    False
2020-01-04    False
2020-01-05     True
dtype: bool

crossed_below method

GenericAccessor.crossed_below(
    other,
    wait=0,
    broadcast_kwargs=None,
    wrap_kwargs=None
)

Generate crossover below another array.

See crossed_above_nb() but in reversed order.


cumprod method

GenericAccessor.cumprod(
    *,
    wrap_kwargs=None
)

See nancumprod_nb().


cumsum method

GenericAccessor.cumsum(
    *,
    wrap_kwargs=None
)

See nancumsum_nb().


describe method

GenericAccessor.describe(
    percentiles=None,
    ddof=1,
    group_by=None,
    wrap_kwargs=None
)

See describe_reduce_nb().

For percentiles, see pd.DataFrame.describe.

Usage

>>> df.vbt.describe()
              a         b        c
count  5.000000  5.000000  5.00000
mean   3.000000  3.000000  1.80000
std    1.581139  1.581139  0.83666
min    1.000000  1.000000  1.00000
25%    2.000000  2.000000  1.00000
50%    3.000000  3.000000  2.00000
75%    4.000000  4.000000  2.00000
max    5.000000  5.000000  3.00000

diff method

GenericAccessor.diff(
    n=1,
    *,
    wrap_kwargs=None
)

See diff_nb().


drawdown method

GenericAccessor.drawdown(
    wrap_kwargs=None
)

Drawdown series.


drawdowns property

GenericAccessor.get_drawdowns() with default arguments.


ewm_mean method

GenericAccessor.ewm_mean(
    span,
    minp=0,
    adjust=True,
    wrap_kwargs=None
)

See ewm_mean_nb().


ewm_std method

GenericAccessor.ewm_std(
    span,
    minp=0,
    adjust=True,
    ddof=1,
    wrap_kwargs=None
)

See ewm_std_nb().


expanding_apply method

GenericAccessor.expanding_apply(
    apply_func_nb,
    *args,
    minp=1,
    on_matrix=False,
    wrap_kwargs=None
)

See expanding_apply_nb() and expanding_matrix_apply_nb() for on_matrix=True.

Usage

>>> mean_nb = njit(lambda i, col, a: np.nanmean(a))
>>> df.vbt.expanding_apply(mean_nb)
              a    b    c
2020-01-01  1.0  5.0  1.0
2020-01-02  1.5  4.5  1.5
2020-01-03  2.0  4.0  2.0
2020-01-04  2.5  3.5  2.0
2020-01-05  3.0  3.0  1.8

>>> mean_matrix_nb = njit(lambda i, a: np.nanmean(a))
>>> df.vbt.expanding_apply(mean_matrix_nb, on_matrix=True)
                   a         b         c
2020-01-01  2.333333  2.333333  2.333333
2020-01-02  2.500000  2.500000  2.500000
2020-01-03  2.666667  2.666667  2.666667
2020-01-04  2.666667  2.666667  2.666667
2020-01-05  2.600000  2.600000  2.600000

expanding_max method

GenericAccessor.expanding_max(
    minp=1,
    *,
    wrap_kwargs=None
)

See expanding_max_nb().


expanding_mean method

GenericAccessor.expanding_mean(
    minp=1,
    *,
    wrap_kwargs=None
)

See expanding_mean_nb().


expanding_min method

GenericAccessor.expanding_min(
    minp=1,
    *,
    wrap_kwargs=None
)

See expanding_min_nb().


expanding_split method

GenericAccessor.expanding_split(
    **kwargs
)

Split using GenericAccessor.split() on ExpandingSplitter.

Usage

>>> train_set, valid_set, test_set = sr.vbt.expanding_split(
...     n=5, set_lens=(1, 1), min_len=3, left_to_right=False)
>>> train_set[0]
split_idx    0    1    2    3    4    5    6  7
0          0.0  0.0  0.0  0.0  0.0  0.0  0.0  0
1          NaN  1.0  1.0  1.0  1.0  1.0  1.0  1
2          NaN  NaN  2.0  2.0  2.0  2.0  2.0  2
3          NaN  NaN  NaN  3.0  3.0  3.0  3.0  3
4          NaN  NaN  NaN  NaN  4.0  4.0  4.0  4
5          NaN  NaN  NaN  NaN  NaN  5.0  5.0  5
6          NaN  NaN  NaN  NaN  NaN  NaN  6.0  6
7          NaN  NaN  NaN  NaN  NaN  NaN  NaN  7
>>> valid_set[0]
split_idx  0  1  2  3  4  5  6  7
0          1  2  3  4  5  6  7  8
>>> test_set[0]
split_idx  0  1  2  3  4  5  6  7
0          2  3  4  5  6  7  8  9

>>> sr.vbt.expanding_split(
...     set_lens=(1, 1), min_len=3, left_to_right=False,
...     plot=True, trace_names=['train', 'valid', 'test'])


expanding_std method

GenericAccessor.expanding_std(
    minp=1,
    ddof=1,
    wrap_kwargs=None
)

See expanding_std_nb().


ffill method

GenericAccessor.ffill(
    *,
    wrap_kwargs=None
)

See ffill_nb().


fillna method

GenericAccessor.fillna(
    value,
    *,
    wrap_kwargs=None
)

See fillna_nb().


filter method

GenericAccessor.filter(
    filter_func_nb,
    *args,
    wrap_kwargs=None
)

See filter_nb().

Usage

>>> greater_nb = njit(lambda i, col, a: a > 2)
>>> df.vbt.filter(greater_nb)
              a    b    c
2020-01-01  NaN  5.0  NaN
2020-01-02  NaN  4.0  NaN
2020-01-03  3.0  3.0  3.0
2020-01-04  4.0  NaN  NaN
2020-01-05  5.0  NaN  NaN

fshift method

GenericAccessor.fshift(
    n=1,
    fill_value=nan,
    *,
    wrap_kwargs=None
)

See fshift_nb().


get_drawdowns method

GenericAccessor.get_drawdowns(
    wrapper_kwargs=None,
    **kwargs
)

Generate drawdown records.

See Drawdowns.


get_ranges method

GenericAccessor.get_ranges(
    wrapper_kwargs=None,
    **kwargs
)

Generate range records.

See Ranges.


groupby_apply method

GenericAccessor.groupby_apply(
    by,
    apply_func_nb,
    *args,
    on_matrix=False,
    wrap_kwargs=None,
    **kwargs
)

See groupby_apply_nb() and groupby_matrix_apply_nb() for on_matrix=True.

For by, see pd.DataFrame.groupby.

Usage

>>> mean_nb = njit(lambda i, col, a: np.nanmean(a))
>>> df.vbt.groupby_apply([1, 1, 2, 2, 3], mean_nb)
     a    b    c
1  1.5  4.5  1.5
2  3.5  2.5  2.5
3  5.0  1.0  1.0

>>> mean_matrix_nb = njit(lambda i, a: np.nanmean(a))
>>> df.vbt.groupby_apply([1, 1, 2, 2, 3], mean_matrix_nb, on_matrix=True)
          a         b         c
1  2.500000  2.500000  2.500000
2  2.833333  2.833333  2.833333
3  2.333333  2.333333  2.333333

histplot method

GenericAccessor.histplot(
    trace_names=None,
    group_by=None,
    return_fig=True,
    **kwargs
)

Create Histogram and return the figure.

Usage

>>> df.vbt.histplot()


idxmax method

GenericAccessor.idxmax(
    group_by=None,
    order='C',
    wrap_kwargs=None
)

Return labeled index of max of non-NaN elements.


idxmin method

GenericAccessor.idxmin(
    group_by=None,
    order='C',
    wrap_kwargs=None
)

Return labeled index of min of non-NaN elements.


lineplot method

GenericAccessor.lineplot(
    **kwargs
)

GenericAccessor.plot() with 'lines' mode.

Usage

>>> df.vbt.lineplot()


mapping property

Mapping.


max method

GenericAccessor.max(
    group_by=None,
    wrap_kwargs=None
)

Return max of non-NaN elements.


maxabs_scale method

GenericAccessor.maxabs_scale(
    *,
    copy=True,
    **kwargs
)

See sklearn.preprocessing.MaxAbsScaler.


mean method

GenericAccessor.mean(
    group_by=None,
    wrap_kwargs=None
)

Return mean of non-NaN elements.


median method

GenericAccessor.median(
    group_by=None,
    wrap_kwargs=None
)

Return median of non-NaN elements.


metrics class variable

Metrics supported by GenericAccessor.

Config({
    "start": {
        "title": "Start",
        "calc_func": "<function GenericAccessor.<lambda> at 0x129e49440>",
        "agg_func": null,
        "tags": "wrapper"
    },
    "end": {
        "title": "End",
        "calc_func": "<function GenericAccessor.<lambda> at 0x129e494e0>",
        "agg_func": null,
        "tags": "wrapper"
    },
    "period": {
        "title": "Period",
        "calc_func": "<function GenericAccessor.<lambda> at 0x129e49580>",
        "apply_to_timedelta": true,
        "agg_func": null,
        "tags": "wrapper"
    },
    "count": {
        "title": "Count",
        "calc_func": "count",
        "inv_check_has_mapping": true,
        "tags": [
            "generic",
            "describe"
        ]
    },
    "mean": {
        "title": "Mean",
        "calc_func": "mean",
        "inv_check_has_mapping": true,
        "tags": [
            "generic",
            "describe"
        ]
    },
    "std": {
        "title": "Std",
        "calc_func": "std",
        "inv_check_has_mapping": true,
        "tags": [
            "generic",
            "describe"
        ]
    },
    "min": {
        "title": "Min",
        "calc_func": "min",
        "inv_check_has_mapping": true,
        "tags": [
            "generic",
            "describe"
        ]
    },
    "median": {
        "title": "Median",
        "calc_func": "median",
        "inv_check_has_mapping": true,
        "tags": [
            "generic",
            "describe"
        ]
    },
    "max": {
        "title": "Max",
        "calc_func": "max",
        "inv_check_has_mapping": true,
        "tags": [
            "generic",
            "describe"
        ]
    },
    "idx_min": {
        "title": "Min Index",
        "calc_func": "idxmin",
        "agg_func": null,
        "inv_check_has_mapping": true,
        "tags": [
            "generic",
            "index"
        ]
    },
    "idx_max": {
        "title": "Max Index",
        "calc_func": "idxmax",
        "agg_func": null,
        "inv_check_has_mapping": true,
        "tags": [
            "generic",
            "index"
        ]
    },
    "value_counts": {
        "title": "Value Counts",
        "calc_func": "<function GenericAccessor.<lambda> at 0x129e49620>",
        "resolve_value_counts": true,
        "check_has_mapping": true,
        "tags": [
            "generic",
            "value_counts"
        ]
    }
})

Returns GenericAccessor._metrics, which gets (deep) copied upon creation of each instance. Thus, changing this config won't affect the class.

To change metrics, you can either change the config in-place, override this property, or overwrite the instance variable GenericAccessor._metrics.


min method

GenericAccessor.min(
    group_by=None,
    wrap_kwargs=None
)

Return min of non-NaN elements.


minmax_scale method

GenericAccessor.minmax_scale(
    feature_range=(0, 1),
    *,
    copy=True,
    clip=False,
    **kwargs
)

See sklearn.preprocessing.MinMaxScaler.


normalize method

GenericAccessor.normalize(
    norm='l2',
    *,
    copy=True,
    **kwargs
)

See sklearn.preprocessing.Normalizer.


pct_change method

GenericAccessor.pct_change(
    n=1,
    *,
    wrap_kwargs=None
)

See pct_change_nb().


plot method

GenericAccessor.plot(
    trace_names=None,
    x_labels=None,
    return_fig=True,
    **kwargs
)

Create Scatter and return the figure.

Usage

>>> df.vbt.plot()


plots_defaults property

Defaults for PlotsBuilderMixin.plots().

Merges PlotsBuilderMixin.plots_defaults and generic.plots from settings.


power_transform method

GenericAccessor.power_transform(
    method='yeo-johnson',
    *,
    standardize=True,
    copy=True,
    **kwargs
)

See sklearn.preprocessing.PowerTransformer.


product method

GenericAccessor.product(
    *,
    wrap_kwargs=None
)

See nanprod_nb().


quantile_transform method

GenericAccessor.quantile_transform(
    *,
    n_quantiles=1000,
    output_distribution='uniform',
    ignore_implicit_zeros=False,
    subsample=10000,
    random_state=None,
    copy=True,
    **kwargs
)

See sklearn.preprocessing.QuantileTransformer.


range_split method

GenericAccessor.range_split(
    **kwargs
)

Split using GenericAccessor.split() on RangeSplitter.

Usage

>>> range_df, range_indexes = sr.vbt.range_split(n=2)
>>> range_df
split_idx  0  1
0          0  5
1          1  6
2          2  7
3          3  8
4          4  9
>>> range_indexes
[DatetimeIndex(['2020-01-01', ..., '2020-01-05'], dtype='datetime64[ns]', name='split_0'),
 DatetimeIndex(['2020-01-06', ..., '2020-01-10'], dtype='datetime64[ns]', name='split_1')]

>>> range_df, range_indexes = sr.vbt.range_split(range_len=4)
>>> range_df
split_idx  0  1  2  3  4  5  6
0          0  1  2  3  4  5  6
1          1  2  3  4  5  6  7
2          2  3  4  5  6  7  8
3          3  4  5  6  7  8  9
>>> range_indexes
[DatetimeIndex(['2020-01-01', ..., '2020-01-04'], dtype='datetime64[ns]', name='split_0'),
 DatetimeIndex(['2020-01-02', ..., '2020-01-05'], dtype='datetime64[ns]', name='split_1'),
 DatetimeIndex(['2020-01-03', ..., '2020-01-06'], dtype='datetime64[ns]', name='split_2'),
 DatetimeIndex(['2020-01-04', ..., '2020-01-07'], dtype='datetime64[ns]', name='split_3'),
 DatetimeIndex(['2020-01-05', ..., '2020-01-08'], dtype='datetime64[ns]', name='split_4'),
 DatetimeIndex(['2020-01-06', ..., '2020-01-09'], dtype='datetime64[ns]', name='split_5'),
 DatetimeIndex(['2020-01-07', ..., '2020-01-10'], dtype='datetime64[ns]', name='split_6')]

>>> range_df, range_indexes = sr.vbt.range_split(start_idxs=[0, 2], end_idxs=[5, 7])
>>> range_df
split_idx  0  1
0          0  2
1          1  3
2          2  4
3          3  5
4          4  6
5          5  7
>>> range_indexes
[DatetimeIndex(['2020-01-01', ..., '2020-01-06'], dtype='datetime64[ns]', name='split_0'),
 DatetimeIndex(['2020-01-03', ..., '2020-01-08'], dtype='datetime64[ns]', name='split_1')]

>>> range_df, range_indexes = sr.vbt.range_split(start_idxs=[0], end_idxs=[2, 3, 4])
>>> range_df
split_idx    0    1  2
0          0.0  0.0  0
1          1.0  1.0  1
2          2.0  2.0  2
3          NaN  3.0  3
4          NaN  NaN  4
>>> range_indexes
[DatetimeIndex(['2020-01-01', ..., '2020-01-03'], dtype='datetime64[ns]', name='split_0'),
 DatetimeIndex(['2020-01-01', ..., '2020-01-04'], dtype='datetime64[ns]', name='split_1'),
 DatetimeIndex(['2020-01-01', ..., '2020-01-05'], dtype='datetime64[ns]', name='split_2')]

>>> range_df, range_indexes = sr.vbt.range_split(
...     start_idxs=pd.Index(['2020-01-01', '2020-01-02']),
...     end_idxs=pd.Index(['2020-01-04', '2020-01-05'])
... )
>>> range_df
split_idx  0  1
0          0  1
1          1  2
2          2  3
3          3  4
>>> range_indexes
[DatetimeIndex(['2020-01-01', ..., '2020-01-04'], dtype='datetime64[ns]', name='split_0'),
 DatetimeIndex(['2020-01-02', ..., '2020-01-05'], dtype='datetime64[ns]', name='split_1')]

 >>> sr.vbt.range_split(
 ...    start_idxs=pd.Index(['2020-01-01', '2020-01-02', '2020-01-01']),
 ...    end_idxs=pd.Index(['2020-01-08', '2020-01-04', '2020-01-07']),
 ...    plot=True
 ... )


ranges property

GenericAccessor.get_ranges() with default arguments.


rebase method

GenericAccessor.rebase(
    base,
    wrap_kwargs=None
)

Rebase all series to a given intial base.

This makes comparing/plotting different series together easier. Will forward and backward fill NaN values.


reduce method

GenericAccessor.reduce(
    reduce_func_nb,
    *args,
    returns_array=False,
    returns_idx=False,
    flatten=False,
    order='C',
    to_index=True,
    group_by=None,
    wrap_kwargs=None
)

Reduce by column.

See flat_reduce_grouped_to_array_nb() if grouped, returns_array is True and flatten is True. See flat_reduce_grouped_nb() if grouped, returns_array is False and flatten is True. See reduce_grouped_to_array_nb() if grouped, returns_array is True and flatten is False. See reduce_grouped_nb() if grouped, returns_array is False and flatten is False. See reduce_to_array_nb() if not grouped and returns_array is True. See reduce_nb() if not grouped and returns_array is False.

Set returns_idx to True if values returned by reduce_func_nb are indices/positions. Set to_index to False to return raw positions instead of labels.

Usage

>>> mean_nb = njit(lambda col, a: np.nanmean(a))
>>> df.vbt.reduce(mean_nb)
a    3.0
b    3.0
c    1.8
dtype: float64

>>> argmax_nb = njit(lambda col, a: np.argmax(a))
>>> df.vbt.reduce(argmax_nb, returns_idx=True)
a   2020-01-05
b   2020-01-01
c   2020-01-03
dtype: datetime64[ns]

>>> argmax_nb = njit(lambda col, a: np.argmax(a))
>>> df.vbt.reduce(argmax_nb, returns_idx=True, to_index=False)
a    4
b    0
c    2
dtype: int64

>>> min_max_nb = njit(lambda col, a: np.array([np.nanmin(a), np.nanmax(a)]))
>>> df.vbt.reduce(min_max_nb, returns_array=True, wrap_kwargs=dict(name_or_index=['min', 'max']))
       a    b    c
min  1.0  1.0  1.0
max  5.0  5.0  3.0

>>> group_by = pd.Series(['first', 'first', 'second'], name='group')
>>> df.vbt.reduce(mean_nb, group_by=group_by)
group
first     3.0
second    1.8
dtype: float64

>>> df.vbt.reduce(min_max_nb, name_or_index=['min', 'max'],
...     returns_array=True, group_by=group_by)
group  first  second
min      1.0     1.0
max      5.0     3.0

resample_apply method

GenericAccessor.resample_apply(
    freq,
    apply_func_nb,
    *args,
    on_matrix=False,
    wrap_kwargs=None,
    **kwargs
)

See groupby_apply_nb() and groupby_matrix_apply_nb() for on_matrix=True.

For freq, see pd.DataFrame.resample.

Usage

>>> mean_nb = njit(lambda i, col, a: np.nanmean(a))
>>> df.vbt.resample_apply('2d', mean_nb)
              a    b    c
2020-01-01  1.5  4.5  1.5
2020-01-03  3.5  2.5  2.5
2020-01-05  5.0  1.0  1.0

>>> mean_matrix_nb = njit(lambda i, a: np.nanmean(a))
>>> df.vbt.resample_apply('2d', mean_matrix_nb, on_matrix=True)
                   a         b         c
2020-01-01  2.500000  2.500000  2.500000
2020-01-03  2.833333  2.833333  2.833333
2020-01-05  2.333333  2.333333  2.333333

resolve_self method

GenericAccessor.resolve_self(
    cond_kwargs=None,
    custom_arg_names=None,
    impacts_caching=True,
    silence_warnings=False
)

Resolve self.

See Wrapping.resolve_self().

Creates a copy of this instance mapping is different in cond_kwargs.


robust_scale method

GenericAccessor.robust_scale(
    *,
    with_centering=True,
    with_scaling=True,
    quantile_range=(25.0, 75.0),
    copy=True,
    unit_variance=False,
    **kwargs
)

See sklearn.preprocessing.RobustScaler.


rolling_apply method

GenericAccessor.rolling_apply(
    window,
    apply_func_nb,
    *args,
    minp=None,
    on_matrix=False,
    wrap_kwargs=None
)

See rolling_apply_nb() and rolling_matrix_apply_nb() for on_matrix=True.

Usage

>>> mean_nb = njit(lambda i, col, a: np.nanmean(a))
>>> df.vbt.rolling_apply(3, mean_nb)
              a    b         c
2020-01-01  1.0  5.0  1.000000
2020-01-02  1.5  4.5  1.500000
2020-01-03  2.0  4.0  2.000000
2020-01-04  3.0  3.0  2.333333
2020-01-05  4.0  2.0  2.000000

>>> mean_matrix_nb = njit(lambda i, a: np.nanmean(a))
>>> df.vbt.rolling_apply(3, mean_matrix_nb, on_matrix=True)
                   a         b         c
2020-01-01  2.333333  2.333333  2.333333
2020-01-02  2.500000  2.500000  2.500000
2020-01-03  2.666667  2.666667  2.666667
2020-01-04  2.777778  2.777778  2.777778
2020-01-05  2.666667  2.666667  2.666667

rolling_max method

GenericAccessor.rolling_max(
    window,
    minp=None,
    *,
    wrap_kwargs=None
)

See rolling_max_nb().


rolling_mean method

GenericAccessor.rolling_mean(
    window,
    minp=None,
    *,
    wrap_kwargs=None
)

See rolling_mean_nb().


rolling_min method

GenericAccessor.rolling_min(
    window,
    minp=None,
    *,
    wrap_kwargs=None
)

See rolling_min_nb().


rolling_split method

GenericAccessor.rolling_split(
    **kwargs
)

Split using GenericAccessor.split() on RollingSplitter.

Usage

>>> train_set, valid_set, test_set = sr.vbt.rolling_split(
...     window_len=5, set_lens=(1, 1), left_to_right=False)
>>> train_set[0]
split_idx  0  1  2  3  4  5
0          0  1  2  3  4  5
1          1  2  3  4  5  6
2          2  3  4  5  6  7
>>> valid_set[0]
split_idx  0  1  2  3  4  5
0          3  4  5  6  7  8
>>> test_set[0]
split_idx  0  1  2  3  4  5
0          4  5  6  7  8  9

>>> sr.vbt.rolling_split(
...     window_len=5, set_lens=(1, 1), left_to_right=False,
...     plot=True, trace_names=['train', 'valid', 'test'])


rolling_std method

GenericAccessor.rolling_std(
    window,
    minp=None,
    ddof=1,
    wrap_kwargs=None
)

See rolling_std_nb().


scale method

GenericAccessor.scale(
    *,
    copy=True,
    with_mean=True,
    with_std=True,
    **kwargs
)

See sklearn.preprocessing.StandardScaler.


scatterplot method

GenericAccessor.scatterplot(
    **kwargs
)

GenericAccessor.plot() with 'markers' mode.

Usage

>>> df.vbt.scatterplot()


shuffle method

GenericAccessor.shuffle(
    seed=None,
    *,
    wrap_kwargs=None
)

See shuffle_nb().


split method

GenericAccessor.split(
    splitter,
    stack_kwargs=None,
    keys=None,
    plot=False,
    trace_names=None,
    heatmap_kwargs=None,
    **kwargs
)

Split using a splitter.

Returns a tuple of tuples, each corresponding to a set and composed of a dataframe and split indexes.

A splitter can be any class instance that has split method, ideally subclassing sklearn.model_selection.BaseCrossValidator or BaseSplitter.

heatmap_kwargs are passed to Heatmap if plot is True, can be a dictionary or a list per set, for example, to set trace name for each set ('train', 'test', etc.).

**kwargs are passed to the split method.

Note

The datetime-like format of the index will be lost as result of this operation. Make sure to store the index metadata such as frequency information beforehand.

Usage

>>> from sklearn.model_selection import TimeSeriesSplit

>>> splitter = TimeSeriesSplit(n_splits=3)
>>> (train_df, train_indexes), (test_df, test_indexes) = sr.vbt.split(splitter)

>>> train_df
split_idx    0    1  2
0          0.0  0.0  0
1          1.0  1.0  1
2          2.0  2.0  2
3          3.0  3.0  3
4          NaN  4.0  4
5          NaN  5.0  5
6          NaN  NaN  6
7          NaN  NaN  7
>>> train_indexes
[DatetimeIndex(['2020-01-01', ..., '2020-01-04'], dtype='datetime64[ns]', name='split_0'),
 DatetimeIndex(['2020-01-01', ..., '2020-01-06'], dtype='datetime64[ns]', name='split_1'),
 DatetimeIndex(['2020-01-01', ..., '2020-01-08'], dtype='datetime64[ns]', name='split_2')]
>>> test_df
split_idx  0  1  2
0          4  6  8
1          5  7  9
>>> test_indexes
[DatetimeIndex(['2020-01-05', '2020-01-06'], dtype='datetime64[ns]', name='split_0'),
 DatetimeIndex(['2020-01-07', '2020-01-08'], dtype='datetime64[ns]', name='split_1'),
 DatetimeIndex(['2020-01-09', '2020-01-10'], dtype='datetime64[ns]', name='split_2')]

>>> sr.vbt.split(splitter, plot=True, trace_names=['train', 'test'])


stats_defaults property

Defaults for StatsBuilderMixin.stats().

Merges StatsBuilderMixin.stats_defaults and generic.stats from settings.


std method

GenericAccessor.std(
    ddof=1,
    group_by=None,
    wrap_kwargs=None
)

Return standard deviation of non-NaN elements.


subplots class variable

Subplots supported by GenericAccessor.

Config({
    "plot": {
        "check_is_not_grouped": true,
        "plot_func": "plot",
        "pass_trace_names": false,
        "tags": "generic"
    }
})

Returns GenericAccessor._subplots, which gets (deep) copied upon creation of each instance. Thus, changing this config won't affect the class.

To change subplots, you can either change the config in-place, override this property, or overwrite the instance variable GenericAccessor._subplots.


sum method

GenericAccessor.sum(
    group_by=None,
    wrap_kwargs=None
)

Return sum of non-NaN elements.


to_mapped method

GenericAccessor.to_mapped(
    dropna=True,
    dtype=None,
    group_by=None,
    **kwargs
)

Convert this object into an instance of MappedArray.


to_returns method

GenericAccessor.to_returns(
    **kwargs
)

Get returns of this object.


transform method

GenericAccessor.transform(
    transformer,
    wrap_kwargs=None,
    **kwargs
)

Transform using a transformer.

A transformer can be any class instance that has transform and fit_transform methods, ideally subclassing sklearn.base.TransformerMixin and sklearn.base.BaseEstimator.

Will fit transformer if not fitted.

**kwargs are passed to the transform or fit_transform method.

Usage

>>> from sklearn.preprocessing import MinMaxScaler

>>> df.vbt.transform(MinMaxScaler((-1, 1)))
              a    b    c
2020-01-01 -1.0  1.0 -1.0
2020-01-02 -0.5  0.5  0.0
2020-01-03  0.0  0.0  1.0
2020-01-04  0.5 -0.5  0.0
2020-01-05  1.0 -1.0 -1.0

>>> fitted_scaler = MinMaxScaler((-1, 1)).fit(np.array([[2], [4]]))
>>> df.vbt.transform(fitted_scaler)
              a    b    c
2020-01-01 -2.0  2.0 -2.0
2020-01-02 -1.0  1.0 -1.0
2020-01-03  0.0  0.0  0.0
2020-01-04  1.0 -1.0 -1.0
2020-01-05  2.0 -2.0 -2.0

value_counts method

GenericAccessor.value_counts(
    normalize=False,
    sort_uniques=True,
    sort=False,
    ascending=False,
    dropna=False,
    group_by=None,
    mapping=None,
    incl_all_keys=False,
    wrap_kwargs=None,
    **kwargs
)

Return a Series/DataFrame containing counts of unique values.

  • Enable normalize flag to return the relative frequencies of the unique values.
  • Enable sort_uniques flag to sort uniques.
  • Enable sort flag to sort by frequencies.
  • Enable ascending flag to sort in ascending order.
  • Enable dropna flag to exclude counts of NaN.
  • Enable incl_all_keys to include all mapping keys, no only those that are present in the array.

Mapping will be applied using apply_mapping() with **kwargs.


zscore method

GenericAccessor.zscore(
    **kwargs
)

Compute z-score using sklearn.preprocessing.StandardScaler.


GenericDFAccessor class

GenericDFAccessor(
    obj,
    mapping=None,
    **kwargs
)

Accessor on top of data of any type. For DataFrames only.

Accessible through pd.DataFrame.vbt.

Superclasses

Inherited members

Subclasses


flatten_grouped method

GenericDFAccessor.flatten_grouped(
    group_by=None,
    order='C',
    wrap_kwargs=None
)

Flatten each group of columns.

See flatten_grouped_nb(). If all groups have the same length, see flatten_uniform_grouped_nb().

Warning

Make sure that the distribution of group lengths is close to uniform, otherwise groups with less columns will be filled with NaN and needlessly occupy memory.

Usage

>>> group_by = pd.Series(['first', 'first', 'second'], name='group')
>>> df.vbt.flatten_grouped(group_by=group_by, order='C')
group       first  second
2020-01-01    1.0     1.0
2020-01-01    5.0     NaN
2020-01-02    2.0     2.0
2020-01-02    4.0     NaN
2020-01-03    3.0     3.0
2020-01-03    3.0     NaN
2020-01-04    4.0     2.0
2020-01-04    2.0     NaN
2020-01-05    5.0     1.0
2020-01-05    1.0     NaN

>>> df.vbt.flatten_grouped(group_by=group_by, order='F')
group       first  second
2020-01-01    1.0     1.0
2020-01-02    2.0     2.0
2020-01-03    3.0     3.0
2020-01-04    4.0     2.0
2020-01-05    5.0     1.0
2020-01-01    5.0     NaN
2020-01-02    4.0     NaN
2020-01-03    3.0     NaN
2020-01-04    2.0     NaN
2020-01-05    1.0     NaN

heatmap method

GenericDFAccessor.heatmap(
    x_labels=None,
    y_labels=None,
    return_fig=True,
    **kwargs
)

Create Heatmap and return the figure.

Usage

>>> df = pd.DataFrame([
...     [0, np.nan, np.nan],
...     [np.nan, 1, np.nan],
...     [np.nan, np.nan, 2]
... ])
>>> df.vbt.heatmap()


squeeze_grouped method

GenericDFAccessor.squeeze_grouped(
    squeeze_func_nb,
    *args,
    group_by=None,
    wrap_kwargs=None
)

Squeeze each group of columns into a single column.

See squeeze_grouped_nb().

Usage

>>> group_by = pd.Series(['first', 'first', 'second'], name='group')
>>> mean_squeeze_nb = njit(lambda i, group, a: np.nanmean(a))
>>> df.vbt.squeeze_grouped(mean_squeeze_nb, group_by=group_by)
group       first  second
2020-01-01    3.0     1.0
2020-01-02    3.0     2.0
2020-01-03    3.0     3.0
2020-01-04    3.0     2.0
2020-01-05    3.0     1.0

ts_heatmap method

GenericDFAccessor.ts_heatmap(
    is_y_category=True,
    **kwargs
)

Heatmap of time-series data.


GenericSRAccessor class

GenericSRAccessor(
    obj,
    mapping=None,
    **kwargs
)

Accessor on top of data of any type. For Series only.

Accessible through pd.Series.vbt.

Superclasses

Inherited members

Subclasses


flatten_grouped method

GenericSRAccessor.flatten_grouped(
    group_by=None,
    order='C',
    wrap_kwargs=None
)

Flatten each group of elements.

Based on GenericDFAccessor.flatten_grouped().


heatmap method

GenericSRAccessor.heatmap(
    x_level=None,
    y_level=None,
    symmetric=False,
    sort=True,
    x_labels=None,
    y_labels=None,
    slider_level=None,
    active=0,
    slider_labels=None,
    return_fig=True,
    fig=None,
    **kwargs
)

Create a heatmap figure based on object's multi-index and values.

If index is not a multi-index, converts Series into a DataFrame and calls GenericDFAccessor.heatmap().

If multi-index contains more than two levels or you want them in specific order, pass x_level and y_level, each (int if index or str if name) corresponding to an axis of the heatmap. Optionally, pass slider_level to use a level as a slider.

Creates Heatmap and returns the figure.

Usage

>>> multi_index = pd.MultiIndex.from_tuples([
...     (1, 1),
...     (2, 2),
...     (3, 3)
... ])
>>> sr = pd.Series(np.arange(len(multi_index)), index=multi_index)
>>> sr
1  1    0
2  2    1
3  3    2
dtype: int64

>>> sr.vbt.heatmap()

  • Using one level as a slider:
>>> multi_index = pd.MultiIndex.from_tuples([
...     (1, 1, 1),
...     (1, 2, 2),
...     (1, 3, 3),
...     (2, 3, 3),
...     (2, 2, 2),
...     (2, 1, 1)
... ])
>>> sr = pd.Series(np.arange(len(multi_index)), index=multi_index)
>>> sr
1  1  1    0
   2  2    1
   3  3    2
2  3  3    3
   2  2    4
   1  1    5
dtype: int64

>>> sr.vbt.heatmap(slider_level=0)


overlay_with_heatmap method

GenericSRAccessor.overlay_with_heatmap(
    other,
    trace_kwargs=None,
    heatmap_kwargs=None,
    add_trace_kwargs=None,
    fig=None,
    **layout_kwargs
)

Plot Series as a line and overlays it with a heatmap.

Args

other : array_like
Second array. Will broadcast.
trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter.
heatmap_kwargs : dict
Keyword arguments passed to GenericDFAccessor.heatmap().
add_trace_kwargs : dict
Keyword arguments passed to add_trace.
fig : Figure or FigureWidget
Figure to add traces to.
**layout_kwargs
Keyword arguments for layout.

Usage

>>> df['a'].vbt.overlay_with_heatmap(df['b'])


plot_against method

GenericSRAccessor.plot_against(
    other,
    trace_kwargs=None,
    other_trace_kwargs=None,
    pos_trace_kwargs=None,
    neg_trace_kwargs=None,
    hidden_trace_kwargs=None,
    add_trace_kwargs=None,
    fig=None,
    **layout_kwargs
)

Plot Series as a line against another line.

Args

other : array_like
Second array. Will broadcast.
trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter.
other_trace_kwargs : dict

Keyword arguments passed to plotly.graph_objects.Scatter for other.

Set to 'hidden' to hide.

pos_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter for positive line.
neg_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter for negative line.
hidden_trace_kwargs : dict
Keyword arguments passed to plotly.graph_objects.Scatter for hidden lines.
add_trace_kwargs : dict
Keyword arguments passed to add_trace.
fig : Figure or FigureWidget
Figure to add traces to.
**layout_kwargs
Keyword arguments for layout.

Usage

>>> df['a'].vbt.plot_against(df['b'])


qqplot method

GenericSRAccessor.qqplot(
    sparams=(),
    dist='norm',
    plot_line=True,
    line_shape_kwargs=None,
    xref='x',
    yref='y',
    fig=None,
    **kwargs
)

Plot probability plot using scipy.stats.probplot.

**kwargs are passed to GenericAccessor.scatterplot().

Usage

>>> pd.Series(np.random.standard_normal(100)).vbt.qqplot()


squeeze_grouped method

GenericSRAccessor.squeeze_grouped(
    squeeze_func_nb,
    *args,
    group_by=None,
    wrap_kwargs=None
)

Squeeze each group of elements into a single element.

Based on GenericDFAccessor.squeeze_grouped().


ts_heatmap method

GenericSRAccessor.ts_heatmap(
    **kwargs
)

Heatmap of time-series data.


volume method

GenericSRAccessor.volume(
    x_level=None,
    y_level=None,
    z_level=None,
    x_labels=None,
    y_labels=None,
    z_labels=None,
    slider_level=None,
    slider_labels=None,
    active=0,
    scene_name='scene',
    fillna=None,
    fig=None,
    return_fig=True,
    **kwargs
)

Create a 3D volume figure based on object's multi-index and values.

If multi-index contains more than three levels or you want them in specific order, pass x_level, y_level, and z_level, each (int if index or str if name) corresponding to an axis of the volume. Optionally, pass slider_level to use a level as a slider.

Creates Volume and returns the figure.

Usage

>>> multi_index = pd.MultiIndex.from_tuples([
...     (1, 1, 1),
...     (2, 2, 2),
...     (3, 3, 3)
... ])
>>> sr = pd.Series(np.arange(len(multi_index)), index=multi_index)
>>> sr
1  1  1    0
2  2  2    1
3  3  3    2
dtype: int64

>>> sr.vbt.volume().show()


MetaGenericAccessor class

MetaGenericAccessor(
    *args,
    **kwargs
)

Meta class that exposes a read-only class property StatsBuilderMixin.metrics.

Superclasses

Inherited members


TransformerT class

TransformerT(
    **kwargs
)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

__ class C__

def meth(self) -> int:
    return 0

def func(x: Proto) -> int: return x.meth()

func(C()) # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...

Superclasses

  • typing.Generic
  • typing.Protocol

fit_transform method

TransformerT.fit_transform(
    *args,
    **kwargs
)

transform method

TransformerT.transform(
    *args,
    **kwargs
)