Код: Выделить всё
import polars
df = polars.DataFrame(dict(
j=[1,2,3],
k=[4,5,6],
l=[7,8,9],
))
Код: Выделить всё
shape: (3, 3)
┌─────┬─────┬─────┐
│ j ┆ k ┆ l │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╡
│ 1 ┆ 4 ┆ 7 │
│ 2 ┆ 5 ┆ 8 │
│ 3 ┆ 6 ┆ 9 │
└─────┴─────┴─────┘
Код: Выделить всё
df = df.filter(
(polars.col('j') == 2) &
(polars.col('k') == 5) &
(polars.col('l') == 8)
)
Код: Выделить всё
shape: (1, 3)
┌─────┬─────┬─────┐
│ j ┆ k ┆ l │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╡
│ 2 ┆ 5 ┆ 8 │
└─────┴─────┴─────┘
Код: Выделить всё
df = df.filter(
polars.concat_list(polars.all()) == [2, 5, 8]
)
# exceptions.ArrowErrorException: NotYetImplemented("Casting from Int64 to LargeList(Field { name: \"item\", data_type: Int64, is_nullable: true, metadata: {} }) not supported")
Я могу создать выражение вручную:
Код: Выделить всё
df = df.filter(
functools.reduce(lambda a, e: a & e, (polars.col(c) == v for c, v in zip(df.columns, [2, 5, 8])))
)
Код: Выделить всё
df = polars.DataFrame(dict(j=[
[1,4,7],
[2,5,8],
[3,6,9],
]))
Код: Выделить всё
shape: (3, 1)
┌───────────┐
│ j │
│ --- │
│ list[i64] │
╞═══════════╡
│ [1, 4, 7] │
│ [2, 5, 8] │
│ [3, 6, 9] │
└───────────┘
Подробнее здесь: https://stackoverflow.com/questions/762 ... ython-list
Мобильная версия