Choosing columns in Python
select takes expressions, so a column set can be described rather than listed.
import polars as pl
frame = pl.DataFrame({
"lang": ["python", "rust"],
"tours": [11, 12],
"steps": [299, 181],
"tpm": [104.5, 98.0],
})
print(frame.select(pl.col("lang", "tpm")))
print(frame.select(pl.all().exclude("lang")).columns)
print(frame.select(pl.col(pl.Int64)).columns)
print(frame.select(pl.all().exclude(pl.Utf8)).columns)
How it works
pl.all()is every column;excluderemoves from a set.pl.colaccepts several names, or a dtype.- Selectors compose, which keeps wide frames manageable.
Keywords and builtins used here
asprint
The run, in numbers
- Lines
- 13
- Characters to type
- 335
- Tokens
- 139
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 79 seconds.
Step 2 of 4 in Expressions, step 6 of 32 in Polars.