Module 2 · Section 2 of 12
Lesson 2.1 - Introduction to DataFrames
Target: ~9 min read - 20 min hands-on
Overview
Pandas has two core objects: a Series (a single labeled column of data) and a DataFrame (a table made of aligned Series - rows and columns, like a spreadsheet). Almost everything in this module is building, slicing, or reshaping a DataFrame.
We'll build a small DataFrame from a dictionary first, then load one from CSV, and get
comfortable with the three commands you'll run on every new dataset: .head() to
preview it, .info() to check types and missing values, and .describe() for a quick
statistical summary.
Why This Matters (Engineering Context)
.info() and .describe() are your first line of defense against bad data - running
them the moment you load a meter export, a lab instrument dump, or a production log
catches an encoding problem, an unexpected NaN, or a column read as text instead of
numbers before it corrupts a downstream analysis. This is true whether you're a
structural, process, power, or manufacturing engineer.
Code-Along
import pandas as pd
import numpy as np
# --- Series: a single labeled column of data ---
# pd.Series wraps a 1-D sequence of values with an index (here the default
# 0..4) and an optional name. Think of it as one column standing on its own.
energy_series = pd.Series([1240.0, 0.0, 3180.5, 2260.1, 890.7], name="energy_kwh")
print(energy_series)
print("\nType:", type(energy_series))
# --- DataFrame: a table of aligned columns ---
# pd.DataFrame from a dict: each key becomes a column name, each list becomes
# that column's values. Every list must be the same length (one value per row).
site_summary = pd.DataFrame({
"site": ["Alpha Plant", "Bravo Fab", "Charlie DC", "Delta Mill", "Echo Lab"],
"sector": ["Chemical", "Semiconductor", "Data Center", "Manufacturing", "R&D"],
"floor_area_m2": [12000, 8600, 5400, 15800, 3200],
"install_year": [2009, 2015, 2019, 2004, 2017],
})
print("\nSite summary DataFrame:")
site_summary
# .head(n): preview the first n rows - a quick look without dumping the whole table
print(site_summary.head(3))
print("==================================")
# .info(): a technical summary - the row count, plus each column's name,
# non-null count, and dtype. Run it on any new dataset to catch missing values
# or a wrong column type before they cause problems downstream.
site_summary.info()
print("==================================")
# .describe(): count / mean / std / min / quartiles / max for every NUMERIC
# column. Text columns (site, sector) are skipped unless you pass include="all".
print(site_summary.describe())
Run it: the Series prints a labeled column of numbers with an auto index (0-4). The
site_summary DataFrame renders as a 5-row x 4-column table. .describe() only
summarizes the numeric columns (floor_area_m2, install_year) - site and sector
are excluded automatically.
Practice Exercises
- [Mechanical] Build a DataFrame of 4 pieces of rotating equipment with columns
tag,rated_kw,run_hours,vibration_mm_s. - Run
.info()on your new DataFrame and explain, in a comment, what theDtypecolumn tells you. - Use
.describe()onsite_summaryand identify which site has the largest floor area - without eyeballing, using themaxrow plus a filter.
# Try the practice exercises here
Knowledge Check
- What is the difference between a Series and a DataFrame?
- Which method shows you data types and missing-value counts at a glance?
- Does
.describe()include text (object) columns by default?
Answer key
- A Series is a single labeled column; a DataFrame is a table of aligned Series
.info()- No - only numeric columns, unless you pass
include='all'
12 / 63 sections · Course home · Join the coaching cohort