vastorbit.VastFrame.narrow¶
- VastFrame.narrow(index: Annotated[str | list[str], 'STRING representing one column or a list of columns'], columns: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, col_name: str = 'column', val_name: str = 'value') VastFrame¶
Returns the Narrow Table of the VastFrame using the input VastColumns.
- Parameters:
index (SQLColumns) – Index(es) used to identify the Row.
columns (SQLColumns, optional) – List of the VastColumns names. If empty, all VastColumns except the index(es) are used.
col_name (str, optional) – Alias of the VastColumn representing the different input VastColumns names as categories.
val_name (str, optional) – Alias of the VastColumn representing the different input VastColumns values.
- Returns:
the narrow table object.
- Return type:
Examples
Let’s begin by importing vastorbit.
import vastorbit as vo
Hint
By assigning an alias to
vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions fromvastorbitare used as intended without interfering with functions from other libraries.For this example, let’s generate a dataset which has multiple columns:
vdf = vo.VastFrame( { "id": [12, 11, 13], "state": [12, 11, 13], "size":[100, 120, 140], "score": [9, 9.5, 4], "extra_info": ['Grey', 'Black', 'White'], } )
123idInteger123stateInteger123sizeInteger123scoreDecimal(11, 1)Abcextra_infoVarchar(5)1 11 11 120 9.5 Black 2 13 13 140 4.0 White 3 12 12 100 9.0 Grey Rows: 1-3 | Columns: 5To focus only on the quantities of interest, we can utilize the
narrowfunction:vdf.narrow("id", col_name = "state", val_name = "score")
123idIntegerAbcstateVarchar(5)123scoreDecimal(11, 1)1 11 score 9.5 2 12 state 12.0 3 13 state 13.0 4 12 score 9.0 5 13 size 140.0 6 12 size 100.0 7 11 size 120.0 8 11 state 11.0 9 13 score 4.0 Rows: 1-9 | Columns: 3Note
The inverse function of
pivotisnarrow. With both, you can preprocess the table either vertically or horizontally. These functions utilize pure SQL statements to perform the job.See also
VastFrame.pivot(): Pivots the VastFrame.