- элементы: ['a', 'b', 'a', 'a']
- категории ['a', 'b', 'c']
В пандах я бы сделал:
Код: Выделить всё
In [31]: pd.Series(pd.Categorical(['a', 'b', 'a', 'a'], categories=['a', 'b', 'c']))
Out[31]:
0 a
1 b
2 a
3 a
dtype: category
Categories (3, object): ['a', 'b', 'c']
https://pola-rs.github.io/polars/py-pol ... rical.html
Подробнее здесь: https://stackoverflow.com/questions/766 ... -in-polars