pandas
26 steps in 7 sets of Python.
The dataframe library that made Python a serious option for data work, and the one whose API you will be reading in other people's notebooks for years. Series and frames, then selecting rows, which is where loc and iloc earn their reputation for confusing everyone once.
Deriving columns, groupby, reshaping and joining, and then time series, which pandas handles better than almost anything else and is the reason a lot of people never leave.
Series & frames
- SeriesA Series is a column: values plus an index that travels with them.
- DataFrameA DataFrame is a dict of Series that share one index.
- Reading CSVread_csv is the front door: point it at text, tell it the types.
- Types and conversionPandas types decide what operations exist and how much memory it costs.
Selecting rows
- Selecting columnsOne column is a Series, a list of columns is a DataFrame.
- loc and ilocloc works in labels, iloc in positions — and mixing them is the classic bug.
- Boolean filteringA boolean Series selects rows; combine conditions with & and |, in brackets.
- Sorting and rankingSort by values or by index, and rank without reordering.
Deriving columns
- Adding columnsassign returns a new frame, which is what makes chaining safe.
- apply, map and vectorizingapply is a loop wearing a nice hat: reach for a vectorized expression first.
- Method chaining with pipepipe puts your own function in a chain, so the whole transform reads top to bottom.
- The .str accessorVectorized string methods, with the same names as Python's own.
- CategoricalsA category column stores each label once, and can carry an order.
Grouping
- groupbySplit by a key, apply a function, combine the answers.
- Aggregating several ways at onceagg names the outputs, so the result needs no renaming afterwards.
- transform and group-relative valuestransform returns a value per row, so it lines up with the original frame.
- Counting valuesvalue_counts is the first thing to run on any categorical column.
- Missing dataFinding gaps, filling them, and deciding when to drop the row instead.
Reshaping & joining
- Merging framesmerge is a SQL join: keys, a how, and suffixes when names collide.
- Stacking framesconcat glues frames together, down the rows or across the columns.
- Pivotingpivot_table reshapes long data into a grid, aggregating where keys repeat.
- Melting back to longmelt is the inverse of a pivot: wide columns become key-value rows.
Time series
- DatesParse to datetime once, then the .dt accessor answers everything else.
- Resampling a time seriesresample is groupby for time: pick a frequency, pick an aggregate.
- Rolling windowsA moving average smooths a noisy series without losing its shape.
Encore
- pd_run_report.pyA pandas report end to end: parse, clean, derive, group and rank.