liveBook · Manning

Pandas

As explained in The Well-Grounded Data Analyst

pandas is a Python software library for working with tabular and labeled data, including data manipulation and analysis.

pandas is a Python library used to turn large, imperfect datasets into analyzable tables. It supports the practical work around an analysis: loading CSV or Excel data, creating and changing columns, combining files, filtering, sorting, grouping, reshaping, and checking assumptions before drawing conclusions. section 3.2.4 section 4.2.4 section 5.2.4

A useful workflow starts with the analytical question rather than a perfect dataset. Combine compatible event files, inspect row and column counts, identify missing values, verify date coverage and daily volumes, then investigate category and brand inconsistencies. Missing session or brand values may be acceptable when they do not affect the immediate product-focused question; anomalies should be examined before they are corrected. section 4.4.1

Common pandas tasks in an iterative analysis include:

  • Load datasets with enough rows for the problem, including files with millions of records. section 4.2.4 section 8.2.4
  • Concatenate same-structure datasets; this is equivalent to a SQL union for the November and December event files. section 4.4.1
  • Profile missing values, value frequencies, distributions, and grouped counts to test data-quality assumptions. section 4.4.1
  • Derive columns and repair inconsistent labels by grouping records by product ID, selecting a justified correction, and merging it back. section 4.4.1
  • Filter a prepared table from interactive selections, then calculate summary metrics and display the returned rows. section 11.2.2

Combining product events before inspection

Read November and December compressed CSV files, concatenate them into one events table, and inspect its shape. The resulting table contains more than seven million rows and nine columns, creating a single basis for checking coverage, missingness, event types, prices, brands, and product categories. section 4.4.1

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

november = pd.read_csv("./data/november.csv.gz")
december = pd.read_csv("./data/december.csv.gz")

events = pd.concat([november, december], axis=0, ignore_index=True)
print(events.shape)

This listing shows the minimum setup: import pandas, read two compressed CSV files, concatenate them by rows, and inspect the resulting table shape. section 4.4.1

pandas can remain the analysis layer while other tools handle specialized work. Matplotlib, seaborn, or ridgeplot can visualize results; scipy can investigate categorical associations; statsmodels and pmdarima can address time-specific analysis and forecasting; scikit-learn can segment data; and Streamlit can turn prepared tables, filters, metrics, charts, and raw rows into an interactive proof of concept. section 6.2.4 section 8.2.4 section 10.2.4 section 12.3.4

How The Well-Grounded Data Analyst covers it

How deep it goes
Demonstrates executable concatenation, inspection, grouping, correction, merging, and filtering, while deferring specialized statistics, forecasting, and clustering to other libraries.
Examples
Uses combined November–December product events and a Streamlit house-price explorer with geographic filters, median prices, charts, and raw-data tables.
What it assumes
Assumes a tool capable of loading files and manipulating tables, while allowing technology choices beyond the Python example stack.
What you can do after
Apply it via pandas to prepare, validate, transform, summarize, and filter large tabular datasets for analysis or prototypes.
How it connects
Connects pandas with NumPy, Matplotlib, seaborn, scipy, statsmodels, pmdarima, scikit-learn, Streamlit, and SQL union operations.

Also explained in

Compare how 11 books explain pandas →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Data Analyst. The section links point to the parts of the book it draws on.