Я использую метод with_columns следующим образом:
Код: Выделить всё
list_of_lists = [
['base', 'base.current base', 'base.current base.inventories - total', 'ABCD'],
['base', 'base.current base', 'base.current base.inventories - total', 'DEFG'],
['base', 'base.current base', 'base.current base.inventories - total', 'ABCD'],
['base', 'base.current base', 'base.current base.inventories - total', 'HIJK']
]
list_of_strings = ['(bobbyJoe460)',
'bobby, Joe (xx866e)',
'137642039575',
'mamamia']
pl_df_1 = pl.DataFrame({'lists': list_of_lists,'stris':list_of_strings}, strict=False)
pl_df_1.with_columns(pl.col(['lists','stris'])
.cast(pl.List(pl.Categorical))
.hash(seed=140)
.name.suffix('_hashed')
)
При включении pl.List код выдаст:
Код: Выделить всё
lists stris lists_hashed stris_hashed
list[str] str u64 u64
["base", "base.current base", … "ABCD"] "(bobbyJoe460)" 11845069150176100519 594396677107
["base", "base.current base", … "DEFG"] "bobby, Joe (xx866e)" 6761150988783483050 594396677107
["base", "base.current base", … "ABCD"] "137642039575" 11845069150176100519 594396677107
["base", "base.current base", … "HIJK"] "mamamia" 8290133271651710679 594396677107
Подробнее здесь: https://stackoverflow.com/questions/794 ... -statement
Мобильная версия