vastorbit.VastFrame.add_duplicates¶
- VastFrame.add_duplicates(weight: int | str, use_gcd: bool = True) VastFrame¶
Duplicates the
VastFrameusing the input weight.- Parameters:
weight (str | integer) –
VastColumnorintegerrepresenting 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:
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
VastFramewith multiple columns:vdf = vo.VastFrame( { "cats": ["A", "B", "C"], "reps": [2, 4, 8], }, )
AbccatsVarchar(1)123repsInteger1 C 8 2 A 2 3 B 4 Rows: 1-3 | Columns: 2We can add duplicates by the weight column:
vdf.add_duplicates("reps")
AbccatsVarchar(1)1 C 2 C 3 B 4 A 5 C 6 B 7 C 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.