Код: Выделить всё
import polars as pl
pl.Config(tbl_cols=10)
schema = [
'x-latest', 'x-mean', 'x-std',
'y-latest', 'y-mean', 'y-std',
'z-latest', 'z-mean', 'z-std'
]
df = pl.DataFrame([range(n, n + 3) for n in range(0, 27, 3)], schema=schema)
Код: Выделить всё
┌──────────┬────────┬───────┬──────────┬────────┬───────┬──────────┬────────┬───────┐
│ x-latest ┆ x-mean ┆ x-std ┆ y-latest ┆ y-mean ┆ y-std ┆ z-latest ┆ z-mean ┆ z-std │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
╞══════════╪════════╪═══════╪══════════╪════════╪═══════╪══════════╪════════╪═══════╡
│ 0 ┆ 3 ┆ 6 ┆ 9 ┆ 12 ┆ 15 ┆ 18 ┆ 21 ┆ 24 │
│ 1 ┆ 4 ┆ 7 ┆ 10 ┆ 13 ┆ 16 ┆ 19 ┆ 22 ┆ 25 │
│ 2 ┆ 5 ┆ 8 ┆ 11 ┆ 14 ┆ 17 ┆ 20 ┆ 23 ┆ 26 │
└──────────┴────────┴───────┴──────────┴────────┴───────┴──────────┴────────┴───────┘
Код: Выделить всё
┌───────────┬────────────┬────────────┐
│ x-stats ┆ y-stats ┆ z-stats │
│ --- ┆ --- ┆ --- │
│ struct[3] ┆ struct[3] ┆ struct[3] │
╞═══════════╪════════════╪════════════╡
│ {0,3,6} ┆ {9,12,15} ┆ {18,21,24} │
│ {1,4,7} ┆ {10,13,16} ┆ {19,22,25} │
│ {2,5,8} ┆ {11,14,17} ┆ {20,23,26} │
└───────────┴────────────┴────────────┘
Код: Выделить всё
cols = ['x', 'y', 'z']
df.select(*[
pl.struct(
latest=f'{c}-latest',
mean=f'{c}-mean',
std=f'{c}-std'
).alias(f'{c}-stats')
for c in cols]
)
Существует ли это?
Подробнее здесь: https://stackoverflow.com/questions/788 ... ucts-using