vastorbit.VastFrame.sort¶
- VastFrame.sort(columns: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | dict) VastFrame¶
Sorts the
VastFrameusing the inputVastColumn.- Parameters:
columns (SQLColumns | dict) – List of the
VastColumnused to sort the data, using asc order or dictionary of all sorting methods. For example, to sort by “column1” ASC and “column2” DESC, write:{"column1": "asc", "column2": "desc"}- Returns:
self
- 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.Let us create a
VastFramewhich we can sort:vdf = vo.VastFrame( { "sales": [10, 11, 9, 20, 6], "cat": ['C', 'B', 'A', 'A', 'B'], }, )
123salesIntegerAbccatVarchar(1)1 10 C 2 9 A 3 6 B 4 11 B 5 20 A Rows: 1-5 | Columns: 2We can conveniently sort the
VastFrameusing a particular column:vdf.sort({"sales": "asc"})
123salesIntegerAbccatVarchar(1)1 6 B 2 9 A 3 10 C 4 11 B 5 20 A Rows: 1-5 | Columns: 2The same operation can also be performed in descending order.
vdf.sort({"sales": "desc"})
123salesIntegerAbccatVarchar(1)1 20 A 2 11 B 3 10 C 4 9 A 5 6 B Rows: 1-5 | Columns: 2Note
Sorting the data is crucial to ensure consistent output. While VAST forgoes the use of indexes for enhanced performance, it does not guarantee a specific order of data retrieval.