Loading...

vastorbit.VastFrame.sort

VastFrame.sort(columns: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | dict) VastFrame

Sorts the VastFrame using the input VastColumn.

Parameters:

columns (SQLColumns | dict) – List of the VastColumn used 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:

VastFrame

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 from vastorbit are used as intended without interfering with functions from other libraries.

Let us create a VastFrame which we can sort:

vdf = vo.VastFrame(
    {
        "sales": [10, 11, 9, 20, 6],
        "cat": ['C', 'B', 'A', 'A', 'B'],
    },
)
123
sales
Integer
Abc
cat
Varchar(1)
110C
29A
36B
411B
520A
Rows: 1-5 | Columns: 2

We can conveniently sort the VastFrame using a particular column:

vdf.sort({"sales": "asc"})
123
sales
Integer
Abc
cat
Varchar(1)
16B
29A
310C
411B
520A
Rows: 1-5 | Columns: 2

The same operation can also be performed in descending order.

vdf.sort({"sales": "desc"})
123
sales
Integer
Abc
cat
Varchar(1)
120A
211B
310C
49A
56B
Rows: 1-5 | Columns: 2

Note

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.

See also

VastFrame.append() : Append a VastFrame with another one or an input_relation.