DEV Community

The Practical Developer
The Practical Developer

Posted on Originally published at practicaldevblog.blogspot.com

Pandas Explained: Tables in Python, Without the Spreadsheet

A spreadsheet is fine until the data grows: a million rows, ten files to combine, or the same cleanup repeated every week. Pandas, a Python library created by Wes McKinney and first released in 2008, gives you spreadsheet-style tables inside code, so the cleanup is written once and runs the same way every time. It is the default first step for data work in Python, from a quick sales summary to the data preparation behind a machine learning model.

DataFrames, filtering, and grouping

Pandas rests on a few distinctive ideas:

  • DataFrames and Series: a DataFrame is a table with named columns, a Series is a single column, and both carry labels, so rows and columns can be picked by name instead of position.
  • Reading real files: one call loads a CSV, a spreadsheet, or a database query into a table, with missing values handled rather than silently dropped.
  • Filtering and selecting: conditions pick out rows, column names pick out columns, and the two combine into queries that read almost like sentences.
  • Grouping and joining: groupby summarises rows by category, merge joins tables on a shared key, and both replace the manual copying that spreadsheets encourage.

A tiny example shows the shape, a sales table filtered and then totalled by city:

import pandas as pd

sales = pd.DataFrame({
    "city": ["Karachi", "Lahore", "Karachi"],
    "amount": [120, 90, 80],
})

big_sales = sales[sales["amount"] >= 100]
print(big_sales)
print(sales.groupby("city")["amount"].sum())
Enter fullscreen mode Exit fullscreen mode

sales["amount"] >= 100 builds a true/false mask, one value per row, and sales[mask] keeps only the rows where it is true, so the Karachi row of 120 survives and the other two do not. groupby("city")["amount"].sum() then adds the amounts per city, giving 200 for Karachi and 90 for Lahore. The original table is untouched; every step returns a new result.

The honest trade

Pandas trades memory for convenience: it loads data into memory, so very large datasets need chunking or a different tool, and its many ways to do the same thing can confuse beginners. When to reach for it: when data fits comfortably in memory and needs cleaning, exploring, or summarising in Python; a database or a distributed tool when the data is too big to hold in memory at all.

Tables, without the spreadsheet

Pandas is tables in Python, without the spreadsheet: DataFrames you can filter, group, and join, in code that reruns exactly. It trades memory for a workflow that scales past copy and paste, and for data that fits on one machine, that trade is usually worth making.

Originally published at https://practicaldevblog.blogspot.com/2026/11/pandas-explained-tables-in-python.html

Top comments (0)