pyarrow.dictionary

pyarrow.dictionary(index_type, value_type, bool ordered=False) DictionaryType

Dictionary (categorical, or simply encoded) type.

Parameters:
index_typeDataType
value_typeDataType
orderedbool
Returns:
typeDictionaryType

Examples

Create an instance of dictionary type:

>>> import pyarrow as pa
>>> pa.dictionary(pa.int64(), pa.utf8())
DictionaryType(dictionary<values=string, indices=int64, ordered=0>)

Use dictionary type to create an array:

>>> pa.array(["a", "b", None, "d"], pa.dictionary(pa.int64(), pa.utf8()))
<pyarrow.lib.DictionaryArray object at ...>
...
-- dictionary:
  [
    "a",
    "b",
    "d"
  ]
-- indices:
  [
    0,
    1,
    null,
    2
  ]