Module 24
pandas
Load, clean, filter, group, and combine table-shaped data with pandas Series and DataFrames.
01
What Is pandas
Meet pandas, the labelled data library built on NumPy, and its two types: the one-dimensional Series and the two-dimensional DataFrame.
02
Creating a Series
Build a Series from a list, a dict, an ndarray, or a single value, and set your own index, dtype, and name while you do it.
03
Series Attributes
Inspect a Series with index, values, dtype, size, shape, ndim, name, and empty, and take a quick look with head and tail.
04
Getting and Setting Series Values
Read Series values by label with loc and by position with iloc, slice both ways, pass lists of labels, and assign new values back.
05
Series Statistics
Summarize a Series with sum, mean, median, std, min and max, describe, value_counts, unique, nunique, nlargest, and cumulative totals.
06
Creating a DataFrame
Build a DataFrame from a dict of columns, a list of rows, a list of dicts, or a dict of Series, and set the index and column order yourself.
07
DataFrame Attributes
Read the shape of a table with shape, size, index, columns, axes and dtypes, then look inside with head, tail, info, and describe.
08
Selecting Columns and Rows
Pull one column or several out of a DataFrame with square brackets, slice rows by position, and learn why chained selection is a poor place to assign.
09
loc and iloc
Select any corner of a DataFrame by label with loc or by position with iloc, and keep the two slicing rules straight in your head.
10
Filtering Rows
Keep the rows you care about with a condition, combine conditions with and and or, and match against a list of values with isin and between.
11
Adding Columns and Rows
Grow a DataFrame: build a new column from a value or an expression, place one at a chosen position, and append rows with loc or concat.
12
Updating Values
Change what is already in a DataFrame: one cell, a whole column, or only the rows that match a condition, with loc, where, mask, and replace.
13
Removing Columns and Rows
Drop columns and rows you do not need, decide between a copy and an in-place change, and find and remove duplicate records.
14
Sorting Data
Order a Series or a DataFrame by its values or by its index, sort on several columns at once, and grab the top rows with nlargest.
15
Column Types and astype
Read the dtype of every column, convert one or several of them with astype, and handle the text that will not turn into a number.
16
Working with Missing Data
Find the gaps in a table with isna, fill them with a sensible value or the value next door, and drop the rows or columns that are too empty to use.
17
Iterating Rows and Columns
Walk a DataFrame row by row with iterrows and itertuples, loop over its columns, and know why whole-column work is usually the better answer.
18
Grouping with groupby
Split a table into groups on one or more columns, then count, total, and average each group with the split, apply, combine pattern.
19
agg, transform, and filter
Ask for several summaries at once with agg, spread a group result back over its rows with transform, and keep whole groups with filter.
20
Combining DataFrames
Stack tables with concat and match them up on a shared column with merge, choosing inner, left, or outer to decide which rows survive.
21
Reading and Writing Files
Load a CSV into a DataFrame, control the separator, header, and index, and write your result back out as CSV, text, or JSON.
22
Exploring a Dataset
Put the module together: load a small dataset, check its shape and gaps, fix the types, then answer real questions with filters and groups.