Код: Выделить всё
import polars as pl
mapping = {
'CASH': {'qty': 1, 'origin': 'E'},
'ITEM': {'qty': -9, 'origin': 'A'},
'CHECK': {'qty': 46, 'origin': 'A'},
}
df = pl.DataFrame([{'type': k} | v for k, v in mapping.items()])\
.with_columns(pl.struct(['qty', 'origin']).alias('mapping'))\
.select(pl.col(['type', 'mapping']))
Код: Выделить всё
shape: (3, 2)
┌───────┬───────────┐
│ type ┆ mapping │
│ --- ┆ --- │
│ str ┆ struct[2] │
╞═══════╪═══════════╡
│ CASH ┆ {1,"E"} │
│ ITEM ┆ {-9,"A"} │
│ CHECK ┆ {46,"A"} │
└───────┴───────────┘
Подробнее здесь: https://stackoverflow.com/questions/788 ... wn-columns
Мобильная версия