Loading...

vastorbit.VastFrame.add_duplicates

VastFrame.add_duplicates(weight: int | str, use_gcd: bool = True) VastFrame

Duplicates the VastFrame using the input weight.

Parameters:
  • weight (str | integer) – VastColumn or integer representing the weight.

  • use_gcd (bool) – If set to True, uses the GCD (Greatest Common Divisor) to reduce all common weights to avoid unnecessary duplicates.

Returns:

the output VastFrame.

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 with multiple columns:

vdf = vo.VastFrame(
    {
        "cats": ["A", "B", "C"],
        "reps": [2, 4, 8],
    },
)
Abc
cats
Varchar(1)
123
reps
Integer
1C8
2A2
3B4
Rows: 1-3 | Columns: 2

We can add duplicates by the weight column:

vdf.add_duplicates("reps")
Abc
cats
Varchar(1)
1C
2C
3B
4A
5C
6B
7C
Rows: 1-7 | Column: cats | Type: varchar(1)

Note

vastorbit will find the greatest common divisor (gcd) of the weight column to normalize the weights by it, ensuring a meaningful minimum number of occurrences. It will then duplicate the different values. This function can be highly valuable in machine learning for preprocessing and increasing the weight of specific rows.

See also

VastFrame.sample() : Sampling the Dataset.