Код: Выделить всё
import polars as pl
df = pl.DataFrame({
'a': [1, 2, 3, 4, 5],
'b': [4, 5, None, 7, 8]
})
df = df.with_columns(interpolate = pl.col('b').interpolate_by('a'))
print(df)
Код: Выделить всё
┌─────┬──────┬─────────────┐
│ a ┆ b ┆ interpolate │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ f64 │
╞═════╪══════╪═════════════╡
│ 1 ┆ 4 ┆ 4.0 │
│ 2 ┆ 5 ┆ 5.0 │
│ 3 ┆ null ┆ 6.0 │
│ 4 ┆ 7 ┆ 7.0 │
│ 5 ┆ 8 ┆ 8.0 │
└─────┴──────┴─────────────┘
Код: Выделить всё
df = pl.DataFrame({
'a': [1, 2, 3, 4, 5],
'b': [4, 5, 6, 7, None]
})
df = df.with_columns(interpolate = pl.col('b').interpolate_by('a'))
print(df)
Код: Выделить всё
shape: (5, 3)
┌─────┬──────┬─────────────┐
│ a ┆ b ┆ interpolate │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ f64 │
╞═════╪══════╪═════════════╡
│ 1 ┆ 4 ┆ 4.0 │
│ 2 ┆ 5 ┆ 5.0 │
│ 3 ┆ 6 ┆ 6.0 │
│ 4 ┆ 7 ┆ 7.0 │
│ 5 ┆ null ┆ null │
└─────┴──────┴─────────────┘
Подробнее здесь: https://stackoverflow.com/questions/794 ... nd-of-a-co