verticapy.vDataFrame.pivot_table#
- vDataFrame.pivot_table(columns: str | list[str], method: Literal['density', 'count', 'avg', 'min', 'max', 'sum'] | str = 'count', of: str | None = None, max_cardinality: tuple[int, int] = (20, 20), h: tuple[int | float | Decimal, int | float | Decimal] = (None, None), fill_none: float = 0.0, mround: int = 3, with_numbers: bool = True, chart: PlottingBase | TableSample | Axes | mFigure | Highchart | Highstock | Figure | None = None, **style_kwargs) PlottingBase | TableSample | Axes | mFigure | Highchart | Highstock | Figure #
Draws the pivot table of one or two columns based on an aggregation.
Parameters#
- columns: SQLColumns
List of the vDataColumns 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
vDataColumns
of
.
- min:
Minimum of the
vDataColumns
of
.
- max:
Maximum of the
vDataColumns
of
.
- sum:
Sum of the
vDataColumns
of
.
- q%:
q Quantile of the
vDataColumns
of
(ex: 50% to get the median).
It can also be a cutomized aggregation (ex: AVG(column1) + 5).
- of: str, optional
The vDataColumn used to compute the aggregation.
- max_cardinality: tuple, optional
Maximum number of distinct elements for vDataColumns 1 and 2 to be used as categorical. For these elements, no h is picked or computed.
- h: tuple, optional
Interval width of the vDataColumns 1 and 2 bars. Only valid if the vDataColumns 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#
- obj
Plotting Object.
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 VerticaPy.
import verticapy as vp
Let’s also import numpy to create a dataset.
import numpy as np
We can create a variable
N
to fix the size:N = 30
Let’s generate a dataset using the following data.
data = vp.vDataFrame( { "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
vDataFrame.
contour()
: Contour Plot.vDataFrame.
scatter_matrix()
: Scatter Matrix.