Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
Arrays

## Displaying

Any array, be it a NumPy array, Pandas object, or even a regular list, can be displayed as a table with ptable, regardless of its size. When the function is called in a IPython environment such as Jupyter Lab, the table will become interactive.

Print out an array in various ways

    vbt.ptable(df)  # (1)!
    vbt.ptable(df, ipython=False)  # (2)!
    vbt.ptable(df, ipython=False, tabulate=False)  # (3)!

1. Choose an appropriate table format based on the current environment
2. Print out the table as a string formatted by `tabulate`
3. Print out the table as a string formatted by Pandas

## Wrapper

A wrapper can be extracted from any array-like object with ArrayWrapper.from_obj.

Extract the wrapper from various objects

    wrapper = data.symbol_wrapper  # (1)!
    wrapper = pf.wrapper  # (2)!
    wrapper = df.vbt.wrapper  # (3)!

    wrapper = vbt.ArrayWrapper.from_obj(sr)  # (4)!

1. `data.wrapper` would return an OHLC wrapper
2. Most VBT objects have an attribute `wrapper`
3. Wrapper of a Pandas Series and DataFrames can be extracted through an accessor
4. Let VBT extract the wrapper

An empty Pandas array can be created with ArrayWrapper.fill.

Create an empty array with the same shape, index, and columns as in another array

    new_float_df = wrapper.fill(np.nan)  # (1)!
    new_bool_df = wrapper.fill(False)  # (2)!
    new_int_df = wrapper.fill(-1)  # (3)!

1. Create a floating array
2. Create a boolean array
3. Create an integer/a categorical array

A NumPy array can be wrapped with a Pandas Series or DataFrame with ArrayWrapper.wrap.

Convert NumPy array to Pandas

    df = wrapper.wrap(arr)

## Product

Product of multiple DataFrames can be achieved with the accessor method BaseAccessor.x. It can be called both as an instance and a class method.

Cross-join columns of multiple DataFrames

    new_df1, new_df2 = df1.vbt.x(df2)  # (1)!
    new_df1, new_df2, new_df3 = df1.vbt.x(df2, df3)  # (2)!
    new_dfs = vbt.pd_acc.x(*dfs)  # (3)!

1. Two DataFrames
2. Three DataFrames
3. Variable number of DataFrames

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings