Код: Выделить всё
import polars as pl
df = pl.from_repr("""
┌──────┬──────┬──────┬──────┬───────────┬───────┐
│ ind1 ┆ ind2 ┆ ind3 ┆ ind4 ┆ my_signal ┆ Value │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ str ┆ i64 │
╞══════╪══════╪══════╪══════╪═══════════╪═══════╡
│ www ┆ xxx ┆ yyy ┆ zzz ┆ a ┆ 1 │
│ www ┆ xxx ┆ yyy ┆ zzz ┆ a ┆ 1 │
│ www ┆ xxx ┆ yyy ┆ zzz ┆ a ┆ 1 │
│ www ┆ xxx ┆ yyy ┆ zzz ┆ b ┆ 2 │
│ fff ┆ xxx ┆ yyy ┆ zzz ┆ b ┆ 2 │
│ fff ┆ xxx ┆ yyy ┆ zzz ┆ b ┆ 2 │
│ fff ┆ xxx ┆ yyy ┆ zzz ┆ c ┆ 3 │
│ fff ┆ xxx ┆ yyy ┆ zzz ┆ c ┆ 3 │
│ fff ┆ xxx ┆ yyy ┆ zzz ┆ c ┆ 3 │
└──────┴──────┴──────┴──────┴───────────┴───────┘
""")
Код: Выделить всё
df.pivot("my_signal", values="Value", aggregate_function="mean")
Код: Выделить всё
shape: (2, 7)
┌──────┬──────┬──────┬──────┬──────┬─────┬──────┐
│ ind1 ┆ ind2 ┆ ind3 ┆ ind4 ┆ a ┆ b ┆ c │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ f64 ┆ f64 ┆ f64 │
╞══════╪══════╪══════╪══════╪══════╪═════╪══════╡
│ www ┆ xxx ┆ yyy ┆ zzz ┆ 1.0 ┆ 2.0 ┆ null │
│ fff ┆ xxx ┆ yyy ┆ zzz ┆ null ┆ 2.0 ┆ 3.0 │
└──────┴──────┴──────┴──────┴──────┴─────┴──────┘
Код: Выделить всё
df = pl.scan_parquet(...)
df.pivot(...)
# AttributeError: 'LazyFrame' object has no attribute 'pivot'
Я хочу сохранить ленивый кадр в конце с помощью Pivoted_df.sink_parquet()
Я пытался использовать .group_by вместо .pivot:
Код: Выделить всё
grouped_df = df.group_by("ind1", "ind2", "ind3", "ind4")
transformed_df = grouped_df.agg(**{f"{col}_mean": pl.col("Value").mean() for col in pl.col('my_signal').unique()})
# TypeError: 'Expr' object is not iterable
Есть ли альтернативы?>
Подробнее здесь: https://stackoverflow.com/questions/784 ... -lazyframe
Мобильная версия