Last modified: May 08, 2026 By Alexander Williams
Select Columns & Filter Rows in Polars
Polars is a fast DataFrame library for Python. It helps you work with large datasets easily. Two basic tasks are selecting columns and filtering rows. This guide shows you how to do both with simple code.
You need to know how to install Polars in Python step by step before starting. Once installed, you can follow along with the examples below.
Creating a Sample DataFrame
First, let's create a DataFrame to work with. We'll use a small dataset about employees.
import polars as pl
# Create a sample DataFrame
data = {
"name": ["Alice", "Bob", "Charlie", "Diana", "Eve"],
"age": [25, 30, 35, 28, 32],
"department": ["Sales", "IT", "Sales", "IT", "HR"],
"salary": [50000, 70000, 55000, 65000, 60000]
}
df = pl.DataFrame(data)
print(df)
shape: (5, 4)
┌─────────┬─────┬────────────┬────────┐
│ name ┆ age ┆ department ┆ salary │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ i32 ┆ str ┆ i32 │
╞═════════╪═════╪════════════╪════════╡
│ Alice ┆ 25 ┆ Sales ┆ 50000 │
│ Bob ┆ 30 ┆ IT ┆ 70000 │
│ Charlie ┆ 35 ┆ Sales ┆ 55000 │
│ Diana ┆ 28 ┆ IT ┆ 65000 │
│ Eve ┆ 32 ┆ HR ┆ 60000 │
└─────────┴─────┴────────────┴────────┘
Selecting Columns in Polars
Selecting columns means picking specific columns from your DataFrame. Polars gives you several ways to do this.
Using select() Method
The select() method is the most common way. You pass column names as strings or expressions.
# Select single column
single_col = df.select("name")
print(single_col)
# Select multiple columns
multi_col = df.select(["name", "salary"])
print(multi_col)
shape: (5, 1)
┌─────────┐
│ name │
│ --- │
│ str │
╞═════════╡
│ Alice │
│ Bob │
│ Charlie │
│ Diana │
│ Eve │
└─────────┘
shape: (5, 2)
┌─────────┬────────┐
│ name ┆ salary │
│ --- ┆ --- │
│ str ┆ i32 │
╞═════════╪════════╡
│ Alice ┆ 50000 │
│ Bob ┆ 70000 │
│ Charlie ┆ 55000 │
│ Diana ┆ 65000 │
│ Eve ┆ 60000 │
└─────────┴────────┘
Using [] Bracket Notation
You can also use square brackets. This is similar to Pandas but works differently in Polars.
# Select columns with brackets
cols = df[["name", "age"]]
print(cols)
shape: (5, 2)
┌─────────┬─────┐
│ name ┆ age │
│ --- ┆ --- │
│ str ┆ i32 │
╞═════════╪═════╡
│ Alice ┆ 25 │
│ Bob ┆ 30 │
│ Charlie ┆ 35 │
│ Diana ┆ 28 │
│ Eve ┆ 32 │
└─────────┴─────┘
Using Column Expressions
Polars supports expressions for advanced selection. You can use pl.col() to reference columns.
# Select with expressions
expr_cols = df.select(pl.col("name"), pl.col("salary") * 1.1)
print(expr_cols)
shape: (5, 2)
┌─────────┬────────────┐
│ name ┆ salary │
│ --- ┆ --- │
│ str ┆ f64 │
╞═════════╪════════════╡
│ Alice ┆ 55000.0 │
│ Bob ┆ 77000.0 │
│ Charlie ┆ 60500.0 │
│ Diana ┆ 71500.0 │
│ Eve ┆ 66000.0 │
└─────────┴────────────┘
Filtering Rows in Polars
Filtering rows means keeping only rows that meet a condition. Polars uses the filter() method for this.
Using filter() Method
Pass a boolean expression to filter(). Only rows where the condition is True remain.
# Filter rows where age > 30
filtered = df.filter(pl.col("age") > 30)
print(filtered)
shape: (2, 4)
┌─────────┬─────┬────────────┬────────┐
│ name ┆ age ┆ department ┆ salary │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ i32 ┆ str ┆ i32 │
╞═════════╪═════╪════════════╪════════╡
│ Charlie ┆ 35 ┆ Sales ┆ 55000 │
│ Eve ┆ 32 ┆ HR ┆ 60000 │
└─────────┴─────┴────────────┴────────┘
Multiple Conditions
You can combine conditions with & (and) or | (or). Always wrap each condition in parentheses.
# Filter: age > 25 AND department is IT
cond = (pl.col("age") > 25) & (pl.col("department") == "IT")
filtered_multi = df.filter(cond)
print(filtered_multi)
shape: (2, 4)
┌─────────┬─────┬────────────┬────────┐
│ name ┆ age ┆ department ┆ salary │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ i32 ┆ str ┆ i32 │
╞═════════╪═════╪════════════╪════════╡
│ Bob ┆ 30 ┆ IT ┆ 70000 │
│ Diana ┆ 28 ┆ IT ┆ 65000 │
└─────────┴─────┴────────────┴────────┘
Filtering with is_in()
Use is_in() to check if a value is in a list. This is useful for categorical data.
# Filter rows where department is Sales or HR
departments = ["Sales", "HR"]
filtered_in = df.filter(pl.col("department").is_in(departments))
print(filtered_in)
shape: (3, 4)
┌─────────┬─────┬────────────┬────────┐
│ name ┆ age ┆ department ┆ salary │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ i32 ┆ str ┆ i32 │
╞═════════╪═════╪════════════╪════════╡
│ Alice ┆ 25 ┆ Sales ┆ 50000 │
│ Charlie ┆ 35 ┆ Sales ┆ 55000 │
│ Eve ┆ 32 ┆ HR ┆ 60000 │
└─────────┴─────┴────────────┴────────┘
Combining Select and Filter
You can chain select() and filter() together. This lets you pick columns and filter rows in one step.
# Select name and salary, then filter salary > 60000
result = df.select(["name", "salary"]).filter(pl.col("salary") > 60000)
print(result)
shape: (2, 2)
┌──────┬────────┐
│ name ┆ salary │
│ --- ┆ --- │
│ str ┆ i32 │
╞══════╪════════╡
│ Bob ┆ 70000 │
│ Diana┆ 65000 │
└──────┴────────┘
Practical Tips
Always use pl.col() for column references. It makes your code clear and works with chaining.
Check your data first. Use Explore Data with Polars Shape, Head to see your DataFrame structure before filtering.
Remember that Polars is lazy by default. Operations are optimized automatically. You don't need to worry about performance.
Common Mistakes
Beginners often forget parentheses in multiple conditions. Always wrap each condition in ().
Another mistake is using Python's and or or inside filter(). Use & and | instead.
If you're switching from Pandas, read Polars vs Pandas: Why Switch? to understand the differences.
Conclusion
Selecting columns and filtering rows are core skills in Polars. Use select() for columns and filter() for rows. Combine them for powerful data manipulation. Practice with your own data to get comfortable. Polars makes data work fast and simple.