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)!
- Choose an appropriate table format based on the current environment
- Print out the table as a string formatted by
tabulate - 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)!
data.wrapperwould return an OHLC wrapper- Most VBT objects have an attribute
wrapper - Wrapper of a Pandas Series and DataFrames can be extracted through an accessor
- 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)!
- Create a floating array
- Create a boolean array
- Create an integer/a categorical array
+
A NumPy array can be wrapped with a Pandas Series or DataFrame with ArrayWrapper.wrap.
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)!
- Two DataFrames
- Three DataFrames
- Variable number of DataFrames