
- pandas: ubiquitous, feature-rich, and integrates with the broader PyData ecosystem (plotting, I/O, modeling).
- Polars: designed for speed and parallelism, often achieving faster queries and lower memory usage for equivalent operations.

Pandas is great for breadth of functionality and ecosystem integration (plotting, modeling, I/O). Polars is worth considering when you need faster query performance or lower memory usage for the same operations.
- These libraries are commonly used inside ETL and preprocessing stages. Many production pipelines operate on small-to-medium datasets that are best handled with pandas or Polars rather than distributed systems.
- Use these tools for repeatable, testable transformations before model training, validation, or reporting.

- Handle missing values
- Remove duplicates
- Standardize data types
- Filter, sort, and perform row/column transformations
- Aggregate for insights
- Merge / join datasets
Detailed patterns and examples
Missing values
Missing or malformed values can skew analyses and break downstream code. Prefer explicit assignment over usinginplace=True to keep transformations clear and avoid deprecation surprises.
Example patterns:
NaN and then decide whether to drop or impute:
Avoid relying on
inplace=True. Assigning the result back to a variable (df = df.dropna()) improves readability, reduces surprises, and is compatible with future pandas behavior.Removing duplicates
Duplicate rows can distort counts and aggregates. Usedrop_duplicates() and specify a subset of columns if you only want uniqueness on specific keys.
Standardizing data types
Consistent data types are crucial for correct math, joins, and model input. Common helpers arepd.to_numeric, pd.to_datetime, and astype.
Filtering and sorting
Use boolean indexing to filter rows andsort_values to order results.
Aggregation (groupby and agg)
Aggregate for reporting or feature engineering withgroupby and agg. Reset the index after aggregation to keep a flat DataFrame.
Merging and joining datasets
Usepd.merge to combine tables — this is conceptually equivalent to SQL joins.
Consolidated example pipeline
The following concise example demonstrates a complete flow: cleaning → conversion → transformation → aggregation → join. This is a practical pattern you can adapt to ETL jobs and MLOps preprocessing steps.Typical transformation flow (conceptual)
- Raw data ingestion (CSV, Parquet, DB, API)
- Missing-value handling (drop or impute per-column)
- Data type standardization (numeric, datetime, categorical)
- Data transformation (filter, compute features, normalize)
- Aggregation (groupby + agg) for summaries or feature creation
- Merge/join to combine related datasets
- pandas documentation: https://pandas.pydata.org/
- Polars documentation: https://www.pola.rs/
- MLOps and ETL best practices: consider idempotent transformations, unit tests for preprocessing logic, and small, testable pipeline steps.