vastorbit.VastFrame.pivot_table¶
- VastFrame.pivot_table(columns: Annotated[str | list[str], 'STRING representing one column or a list of columns'], method: Literal[None, 'density', 'count', 'avg', 'min', 'max', 'sum'] | str = 'count', of: str | None = None, max_cardinality: tuple[int, int] = (20, 20), h: tuple[Annotated[int | float | Decimal, 'Python Numbers'], Annotated[int | float | Decimal, 'Python Numbers']] = (None, None), fill_none: float = 0.0, mround: int = 3, with_numbers: bool = True, chart: PlottingBase | TableSample | Axes | mFigure | Figure | None = None, **style_kwargs) PlottingBase | TableSample | Axes | mFigure | Figure¶
Draws the pivot table of one or two columns based on an aggregation.
- Parameters:
columns (SQLColumns) – List of the VastColumns names. The list must have one or two elements.
method (str, optional) –
The method used to aggregate the data.
- count:
Number of elements.
- density:
Percentage of the distribution.
- mean:
Average of the
VastColumnsof.
- min:
Minimum of the
VastColumnsof.
- max:
Maximum of the
VastColumnsof.
- sum:
Sum of the
VastColumnsof.
- q%:
q Quantile of the
VastColumnsof(ex: 50% to get the median).
It can also be a cutomized aggregation (ex: AVG(column1) + 5).
of (str, optional) – The VastColumn used to compute the aggregation.
max_cardinality (tuple, optional) – Maximum number of distinct elements for VastColumns 1 and 2 to be used as categorical. For these elements, no h is picked or computed.
h (tuple, optional) – Interval width of the VastColumns 1 and 2 bars. Only valid if the VastColumns are numerical. Optimized h will be computed if the parameter is empty or invalid.
fill_none (float, optional) – The empty values of the pivot table are filled by this number.
mround (int, optional) – Rounds the coefficient using the input number of digits. It is only used to display the final pivot table.
with_numbers (bool, optional) – If set to True, no number is displayed in the final drawing.
chart (PlottingObject, optional) – The chart object to plot on.
**style_kwargs – Any optional parameter to pass to the plotting functions.
- Returns:
Plotting Object.
- Return type:
obj
Examples
Note
The below example is a very basic one. For other more detailed examples and customization options, please see Pivot Table
Let’s begin by importing vastorbit.
import vastorbit as vo
Let’s also import numpy to create a dataset.
import numpy as np
We can create a variable
Nto fix the size:N = 30
Let’s generate a dataset using the following data.
data = vo.VastFrame( { "category1": [np.random.choice(['A','B','C']) for _ in range(N)], "category2": [np.random.choice(['D','E']) for _ in range(N)], } )
Below are examples of one types of pivot_table plots:
Pivot Plot
data.pivot_table(columns = ["category1", "category2"])
See also
VastFrame.contour(): Contour Plot.VastFrame.scatter_matrix(): Scatter Matrix.