Question Details

No question body available.

Tags

python dataframe python-polars

Answers (3)

Accepted Answer Available
Accepted Answer
April 29, 2025 Score: 1 Rep: 5,399 Quality: High Completeness: 80%

You need to collapse the multiple-generated-expressions (imagine three matrices come out of that first pl.all(), one for each column) into a single column. You can do that with pl.allhorizontal(your, columns, here):

>>> df.filter(pl.allhorizontal(pl.col('*').isnot_null())) shape: (3, 3) ┌─────┬───────────┬───────────┐ │ id ┆ variable1 ┆ variable2 │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ i64 │ ╞═════╪═══════════╪═══════════╡ │ 1 ┆ 15 ┆ 40 │ │ 3 ┆ 5 ┆ 50 │ │ 4 ┆ 10 ┆ 10 │ └─────┴───────────┴───────────┘
April 29, 2025 Score: 3 Rep: 119,217 Quality: Medium Completeness: 50%

>>> df.filter(pl.allhorizontal(pl.all().isnot_null())) shape: (3, 3) ┌─────┬───────────┬───────────┐ │ id ┆ variable1 ┆ variable2 │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ i64 │ ╞═════╪═══════════╪═══════════╡ │ 1 ┆ 15 ┆ 40 │ │ 3 ┆ 5 ┆ 50 │ │ 4 ┆ 10 ┆ 10 │ └─────┴───────────┴───────────┘
April 29, 2025 Score: 1 Rep: 24,546 Quality: Medium Completeness: 60%

This is probably one place where it's useful to know that pl.all() is shorthand for pl.col("")

pl.all()

pl.col("
")

It just means "all column names" in this sense. (i.e. SELECT * from SQL)

The allhorizontal() is still required.

df.filter(pl.all
horizontal(pl.all().isnotnull()))

shape: (3, 3) ┌─────┬───────────┬───────────┐ │ id ┆ variable1 ┆ variable2 │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ i64 │ ╞═════╪═══════════╪═══════════╡ │ 1 ┆ 15 ┆ 40 │ │ 3 ┆ 5 ┆ 50 │ │ 4 ┆ 10 ┆ 10 │ └─────┴───────────┴───────────┘