Column

Python

PySpark - Substring from Column

String manipulation is fundamental to data engineering workflows, especially when dealing with raw data that requires cleaning, parsing, or transformation. PySpark’s DataFrame API provides a…

Read more →
Python

PySpark - Length of String Column

Calculating string lengths is a fundamental operation in data engineering workflows. Whether you’re validating data quality, detecting truncated records, enforcing business rules, or preparing data…

Read more →
Python

PySpark - Get Column Names as List

Working with PySpark DataFrames frequently requires programmatic access to column names. Whether you’re building dynamic ETL pipelines, validating schemas across environments, or implementing…

Read more →
Pandas

Pandas - Set/Reset Column as Index

• Setting a column as an index transforms it from regular data into row labels, enabling faster lookups and more intuitive data alignment—use set_index() for single or multi-level indexes without…

Read more →
Pandas

Pandas - Rename Column by Index

When working with DataFrames from external sources, you’ll frequently encounter datasets with auto-generated column names, duplicate headers, or names that don’t follow Python naming conventions….

Read more →
Pandas

Pandas - Rename Column Names

The rename() method is the most versatile approach for changing column names in Pandas. It accepts a dictionary mapping old names to new names and returns a new DataFrame by default.

Read more →
Pandas

Pandas - Rank Values in Column

• Pandas provides multiple ranking methods (average, min, max, first, dense) that handle tied values differently, with the rank() method offering fine-grained control over ranking behavior

Read more →
Pandas

Pandas - GroupBy Single Column

The groupby() method partitions a DataFrame based on unique values in a specified column. This operation doesn’t immediately compute results—it creates a GroupBy object that holds instructions for…

Read more →
Pandas

Pandas - Convert Column to Integer

• Converting columns to integers in Pandas requires handling null values first, as standard int types cannot represent missing data—use Int64 (nullable integer) or fill/drop nulls before conversion

Read more →
Pandas

Pandas - Apply Function to Column

• The apply() method transforms DataFrame columns using custom functions, lambda expressions, or built-in functions, offering more flexibility than vectorized operations for complex transformations

Read more →
Pandas

How to Explode a Column in Pandas

When working with real-world data, you’ll frequently encounter columns containing list-like values. Maybe you’re parsing JSON from an API, dealing with multi-select form fields, or processing…

Read more →
Python

How to Explode a Column in Polars

Data rarely arrives in the clean, normalized format you need. JSON APIs return nested arrays. Aggregation operations produce list columns. CSV files contain comma-separated values stuffed into single…

Read more →
Pandas

How to Delete a Column in Pandas

Deleting columns from a DataFrame is one of the most frequent operations in data cleaning. Whether you’re removing irrelevant features before model training, dropping columns with too many null…

Read more →
Python

How to Delete a Column in Polars

Deleting columns from a DataFrame is one of the most common data manipulation tasks. Whether you’re cleaning up temporary calculations, removing sensitive data before export, or trimming down a wide…

Read more →
Pandas

How to Add a New Column in Pandas

Adding columns to a Pandas DataFrame is one of the most common operations you’ll perform in data analysis. Whether you’re calculating derived metrics, categorizing data, or preparing features for…

Read more →
Python

How to Add a New Column in Polars

If you’re coming from pandas, your first instinct might be to write df['new_col'] = value. That won’t work in Polars. The library takes an immutable approach to DataFrames—every transformation…

Read more →
Engineering

Apache Spark - Column Pruning

Column pruning is one of Spark’s most impactful automatic optimizations, yet many developers never think about it—until their jobs run ten times slower than expected. The concept is straightforward:…

Read more →