Categorical Column Map

Module: ppc_robot_lib.utils.categorical_column_map

class CategoricalColumnMap[source]

Structure for assigning auto-incrementing indexes for unique values and creates a mapping of values to indexes.

These values can be used to construct categorical columns to save memory.

Example:

>>> mapping = CategoricalColumnMap()
>>> mapping.get_index('a1')
0
>>> mapping.get_index('a2')
1
>>> mapping.get_index('a1')
0
>>> mapping.get_index('a2')
1
>>> mapping.get_index('a3')
2
>>> mapping.values
{'a1': 0, 'a2': 1, 'a3': 2}
get_index(value)[source]

Adds a new value to the mapping. If the value already exists, previous index is returned. If not, a new one is assigned.

Parameters:

value (Hashable) – Value to add.

Return type:

int

Returns:

Index assigned to the value.

property values: dict[Hashable, int]
Returns:

Dictionary with currently assigned values.