4. Pandas#
Overview
Pandas is the main Python library for working with table-shaped data. In this chapter, you will learn how pandas represents business data with labeled rows and columns, how to read datasets from files, how to inspect and select parts of a table, and how to prepare data for later visualization and statistical work.
By the end of the chapter, you should be ready to use pandas for common management data tasks:
represent one-dimensional and two-dimensional data with Series and DataFrames
load CSV and Excel files into pandas
inspect rows, columns, labels, data types, and missing values
select, filter, sort, and transform table columns
aggregate and combine data for analysis workflows
Chapter Video
Video credit: Python Pandas Tutorial (Part 1): Getting Started with Data Analysis by Corey Schafer.
This embedded video is provided for educational reference only. All rights are retained by the respective copyright holder.
Learning Objectives
By the end of this chapter, you will be able to:
Explain how pandas Series and DataFrames organize labeled business data.
Load CSV, Excel, HTML, and SQL data sources into pandas objects.
Inspect DataFrame rows, columns, indexes, data types, shape, and summary statistics.
Select, filter, transform, sort, aggregate, and combine DataFrame values.
Detect, interpret, drop, and fill missing values in pandas workflows.
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Pandas |
A Python library for working with labeled, table-shaped data. |
2 |
Series |
A one-dimensional labeled pandas object. |
3 |
DataFrame |
A two-dimensional pandas object with rows and columns. |
4 |
Index |
The labels used to identify rows or Series values. |
5 |
Column |
A named vertical set of values in a DataFrame. |
6 |
Row |
One horizontal record in a DataFrame. |
7 |
Label |
A name used to identify a row, column, or value. |
8 |
dtype |
The data type pandas assigns to a Series or DataFrame column. |
9 |
Object dtype |
A pandas dtype commonly used for strings or mixed Python objects. |
10 |
Nullable dtype |
A pandas dtype that can preserve missing values without forcing ordinary Python or NumPy type conversions. |
11 |
CSV file |
A comma-separated values file used to store table data as plain text. |
12 |
Excel file |
A spreadsheet file format that pandas can read and write. |
13 |
HTML table |
A table embedded in a web page that pandas can import. |
14 |
SQL query |
A database request that pandas can use to read table results. |
15 |
read_csv() |
A pandas function for loading CSV files. |
16 |
read_excel() |
A pandas function for loading Excel files. |
17 |
head() |
A method that displays the first rows of a Series or DataFrame. |
18 |
tail() |
A method that displays the last rows of a Series or DataFrame. |
19 |
info() |
A method that summarizes column names, non-null counts, and data types. |
20 |
describe() |
A method that computes summary statistics for numeric or categorical columns. |
21 |
shape |
A tuple describing the number of rows and columns in a DataFrame. |
22 |
loc |
Label-based selection for rows and columns. |
23 |
iloc |
Position-based selection for rows and columns. |
24 |
Boolean indexing |
Selecting rows with a True/False condition. |
25 |
Missing data |
Values that are absent, unknown, or not recorded. |
26 |
NaN |
A floating-point marker often used for missing numerical data. |
27 |
NA |
Pandas missing-value scalar for nullable dtypes. |
28 |
isna() |
A method that detects missing values. |
29 |
dropna() |
A method that removes rows or columns with missing values. |
30 |
fillna() |
A method that replaces missing values with specified values. |
31 |
concat() |
A pandas function for stacking or joining objects along an axis. |
32 |
merge() |
A pandas function for combining DataFrames by matching key columns. |
33 |
join() |
A DataFrame method for combining data by index or key. |
34 |
GroupBy |
A split-apply-combine workflow for grouped summaries. |
35 |
Aggregation |
A calculation that reduces many values into a summary value. |
36 |
map() |
A Series method for substituting or transforming values. |
37 |
apply() |
A method for applying a function across Series or DataFrame values. |
38 |
inplace |
An argument that asks pandas to modify an object directly instead of returning a modified copy. |