Last modified: May 08, 2026 By Alexander Williams
Polars Columns: Add, Rename & Drop
Working with columns is a core part of data manipulation. In Polars, adding, renaming, and dropping columns is fast and intuitive. This guide walks you through each operation with simple examples. You will learn how to transform your DataFrames efficiently.
Polars is built for speed. Its column operations are lazy by default. This means they only execute when you need the result. This makes your code both fast and memory efficient. Let's start with the basics.
Adding Columns in Polars
Adding a new column is common. You might need to create a calculated field. Or you might want to add a constant value. Polars offers several ways to do this.
The most direct method is using the with_columns method. It takes one or more expressions. Each expression defines a new column. Here is an example.
import polars as pl
# Create a simple DataFrame
df = pl.DataFrame({
"name": ["Alice", "Bob", "Charlie"],
"sales": [100, 200, 150]
})
# Add a new column with a constant value
df_with_bonus = df.with_columns(
pl.lit(50).alias("bonus")
)
print(df_with_bonus)
shape: (3, 3)
┌─────────┬───────┬───────┐
│ name ┆ sales ┆ bonus │
│ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ i64 │
╞═════════╪═══════╪═══════╡
│ Alice ┆ 100 ┆ 50 │
│ Bob ┆ 200 ┆ 50 │
│ Charlie ┆ 150 ┆ 50 │
└─────────┴───────┴───────┘
Note:pl.lit() creates a literal column. The alias method names the new column. You can also add calculated columns. For example, add 10% commission to sales.
# Add a calculated column
df_with_commission = df.with_columns(
(pl.col("sales") * 0.1).alias("commission")
)
print(df_with_commission)
shape: (3, 3)
┌─────────┬───────┬────────────┐
│ name ┆ sales ┆ commission │
│ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ f64 │
╞═════════╪═══════╪═══════════╡
│ Alice ┆ 100 ┆ 10.0 │
│ Bob ┆ 200 ┆ 20.0 │
│ Charlie ┆ 150 ┆ 15.0 │
└─────────┴───────┴────────────┘
You can add multiple columns in one call. Just separate expressions with commas. This keeps your code clean and efficient. For more on selecting and filtering, see our guide on Select Columns & Filter Rows in Polars.
Renaming Columns in Polars
Renaming columns helps make your data more readable. Polars provides the rename method. You can rename one or many columns at once.
The simplest way is to pass a dictionary. The keys are old names. The values are new names. Here is an example.
# Rename a single column
df_renamed = df.rename({"sales": "revenue"})
print(df_renamed)
shape: (3, 2)
┌─────────┬─────────┐
│ name ┆ revenue │
│ --- ┆ --- │
│ str ┆ i64 │
╞═════════╪═════════╡
│ Alice ┆ 100 │
│ Bob ┆ 200 │
│ Charlie ┆ 150 │
└─────────┴─────────┘
Tip: You can also rename multiple columns. Just add more key-value pairs to the dictionary. This is faster than renaming one by one.
# Rename multiple columns
df_multi_rename = df.rename({
"name": "employee",
"sales": "revenue"
})
print(df_multi_rename)
shape: (3, 2)
┌──────────┬─────────┐
│ employee ┆ revenue │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════════╪═════════╡
│ Alice ┆ 100 │
│ Bob ┆ 200 │
│ Charlie ┆ 150 │
└──────────┴─────────┘
You can also use a lambda function. This is useful for bulk renaming. For example, make all column names uppercase.
# Rename using a function
df_upper = df.rename(lambda col: col.upper())
print(df_upper)
shape: (3, 2)
┌─────────┬───────┐
│ NAME ┆ SALES │
│ --- ┆ --- │
│ str ┆ i64 │
╞═════════╪═══════╡
│ Alice ┆ 100 │
│ Bob ┆ 200 │
│ Charlie ┆ 150 │
└─────────┴───────┘
Renaming does not modify the original DataFrame. It returns a new one. To keep changes, assign the result to a variable. For more on exploring your data, check out Explore Data with Polars Shape, Head.
Dropping Columns in Polars
Dropping columns removes unnecessary data. This simplifies your DataFrame. Polars uses the drop method. It is straightforward.
Pass the column name as a string. To drop multiple columns, pass a list of strings. Here is how it works.
# Drop a single column
df_dropped = df.drop("sales")
print(df_dropped)
shape: (3, 1)
┌─────────┐
│ name │
│ --- │
│ str │
╞═════════╡
│ Alice │
│ Bob │
│ Charlie │
└─────────┘
Important: Dropping columns is safe. If the column does not exist, Polars raises an error. Always check your column names first. You can drop multiple columns like this.
# Drop multiple columns
df_drop_multi = df.drop(["name", "sales"])
print(df_drop_multi)
shape: (3, 0)
┌─────┐
│ │
│ --- │
│ │
╞═════╡
│ │
│ │
│ │
└─────┘
You can also drop columns using a condition. For example, drop all columns that start with a certain prefix. Use the drop method with a regular expression. This is powerful for cleaning large datasets.
# Drop columns matching a pattern
df_pattern = pl.DataFrame({
"temp_1": [1, 2],
"temp_2": [3, 4],
"final": [5, 6]
})
df_clean = df_pattern.drop(regex=r"^temp_.*")
print(df_clean)
shape: (2, 1)
┌───────┐
│ final │
│ --- │
│ i64 │
╞═══════╡
│ 5 │
│ 6 │
└───────┘
Dropping columns is useful when you prepare data for analysis. It reduces memory usage. It also speeds up further operations. For more on reading and writing files with Polars, see Read & Write Files with Polars.
Combining Operations
You can chain these operations together. This is a key feature of Polars. It makes your code concise and readable. Here is an example.
# Chain add, rename, and drop
result = (df
.with_columns(
(pl.col("sales") * 0.05).alias("tax")
)
.rename({"sales": "gross"})
.drop("name")
)
print(result)
shape: (3, 2)
┌───────┬──────┐
│ gross ┆ tax │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞═══════╪══════╡
│ 100 ┆ 5.0 │
│ 200 ┆ 10.0 │
│ 150 ┆ 7.5 │
└───────┴──────┘
Note: Chaining works because each method returns a new DataFrame. This is efficient in Polars. It does not copy data unnecessarily. The operations are optimized for speed.
Conclusion
Adding, renaming, and dropping columns in Polars is simple. Use with_columns to add new data. Use rename to change column names. Use drop to remove columns you do not need. These methods are fast and flexible.
Remember to chain operations for clean code. Always check your column names to avoid errors. Polars handles large datasets with ease. Start using these techniques today. For a deeper understanding, explore our Polars DataFrames and Series Guide.