vDataFrame.pivot_table¶
In [ ]:
vDataFrame.pivot_table(columns: list,
method: str = "count",
of: str = "",
max_cardinality: tuple = (6, 6),
h: tuple = (None, None),
show: bool = True,
with_numbers: bool = True,
fill_none: float = 0.0,
ax=None,
**style_kwds,)
Draws the pivot table of one or two columns based on an aggregation.
Parameters¶
Name | Type | Optional | Description |
---|---|---|---|
columns | list | ❌ | List of the vcolumns names. The list must have one or two elements. |
method | str | ✓ | The method to use to aggregate the data.
|
of | str | ✓ | The vcolumn to use to compute the aggregation. |
h | tuple | ✓ | Interval width of the vcolumns 1 and 2 bars. It is only valid if the vcolumns are numerical. Optimized h will be computed if the parameter is empty or invalid. |
max_cardinality | tuple | ✓ | Maximum number of distinct elements for vcolumns 1 and 2 to be used as categorical (No h will be picked or computed) |
show | bool | ✓ | If true, the result will be drawn using Matplotlib. |
with_numbers | bool | ✓ | If true, no number will be displayed in the final drawing. |
fill_none | float | ✓ | The empty values of the pivot table will be filled by this number. |
ax | Matplotlib axes object | ✓ | The axes to plot on. |
**style_kwds | any | ✓ | Any optional parameter to pass to the Matplotlib functions. |
Returns¶
tablesample : An object containing the result. For more information, see utilities.tablesample.
Example¶
In [1]:
from verticapy.datasets import load_titanic
titanic = load_titanic()
display(titanic)
In [3]:
titanic.pivot_table(["survived", "pclass"],)
Out[3]:
In [4]:
# Avg of survived partitioned by pclass, age
titanic.pivot_table(["age", "pclass"], method = "avg", of = "survived")
Out[4]:
In [5]:
# Avg of survived partitioned by age, fare
# age will be discretized using an interval of 10 years
# fare will be discretized using an interval of 50£
titanic.pivot_table(["age", "fare"],
method = "avg",
of = "survived",
h = (10, 50))
Out[5]: