# pandas for Tabular Data

> Loading, filtering, joining, grouping and reshaping tables, the daily bread of data scientists before and after modelling. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/pandas
Last updated: 2026-11-28

Loading, filtering, joining, grouping and reshaping tables, the daily bread of data scientists before and after modelling.

Beginner · about 14 hours · difficulty 2/5

Learn first: [NumPy and Array Thinking](https://www.internhack.in/roadmaps/tracks/machine-learning/numpy)

Most real ML problems begin as tables: CSV exports, database dumps, logs. pandas gives you the `DataFrame`, a labelled table with typed columns, plus a huge toolkit for wrangling it.

### Core operations

- **I/O**: `read_csv`, `read_parquet`, `read_sql`; set `dtype` and `parse_dates` explicitly.
- **Selection**: `df.loc` (labels) versus `df.iloc` (positions), boolean filtering, `query`.
- **Transformation**: new columns, `assign`, vectorized string (`.str`) and datetime (`.dt`) accessors.
- **Aggregation**: `groupby(...).agg(...)` is the single most useful pattern for features and reports.
- **Combining**: `merge` (SQL-like joins), `concat`; check row counts before and after every join.
- **Reshaping**: `pivot_table`, `melt`, `stack`.
- **Missing data**: `isna`, `fillna`, `dropna`, and understanding `NaN` semantics.

### Pitfalls

`SettingWithCopyWarning` means you may be editing a temporary copy. Row-wise `apply` is slow; look for a vectorized method first. Many-to-many merges silently multiply rows. For data that does not fit in memory look at Polars or DuckDB later.

**Good enough to move on** when you can take two related raw tables, join them, engineer a few grouped aggregates and export a clean modelling table without copying code from Stack Overflow for every step.

## Key concepts

- **Series and DataFrame**
- **loc, iloc and boolean filters**
- **groupby and aggregation**
- **merge and concat**
- **pivot_table and melt**
- **String and datetime accessors**
- **Parquet and dtypes**
- **Polars**: Faster DataFrame library

## Mini project

Using the public NYC TLC taxi trip data (one month in Parquet), compute average fare and trip duration by hour of day and pickup zone, joined with the zone lookup table.

## Check yourself

You merge orders with customers and the row count grows. What does that tell you about the join keys?

## Free resources

- [pandas user guide](https://pandas.pydata.org/docs/user_guide/) (pandas)
- [Kaggle Learn: Pandas](https://www.kaggle.com/learn/pandas) (Kaggle)

Previous: [NumPy and Array Thinking](https://www.internhack.in/roadmaps/tracks/machine-learning/numpy) · Next: [Visualization with Matplotlib and Seaborn](https://www.internhack.in/roadmaps/tracks/machine-learning/data-visualization)

## More in Python and the Data Workbench

- [Python for Machine Learning](https://www.internhack.in/roadmaps/tracks/machine-learning/python-for-ml)
- [Environments, Packages and Jupyter](https://www.internhack.in/roadmaps/tracks/machine-learning/environments-and-notebooks)
- [NumPy and Array Thinking](https://www.internhack.in/roadmaps/tracks/machine-learning/numpy)
- [pandas for Tabular Data](https://www.internhack.in/roadmaps/tracks/machine-learning/pandas)
- [Visualization with Matplotlib and Seaborn](https://www.internhack.in/roadmaps/tracks/machine-learning/data-visualization)
- [Git for ML Projects](https://www.internhack.in/roadmaps/tracks/machine-learning/git-for-ml)
- [SQL for Pulling Training Data](https://www.internhack.in/roadmaps/tracks/machine-learning/sql-for-data)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
