← All 197 books pandas, one method per page
One method per page

pandas, one method per page

Twenty-four lessons on the pandas methods beginners actually meet: loc, iloc, at, iat; df[mask], isin, query, where; sort_values, reset_index, head, nlargest; dropna, fillna, isna, drop_duplicates; merge, concat, join, assign; groupby, agg, value_counts, one honest hour; every method meaning traced to this box's cached pandas docs pages, and every returned value read whole from a twenty-four line method sweep pandas 3.1.2 on python 3.14.9 ran on this box on the fifth of December, 2026, one call, one return, one mutate check and one surprise per line, nothing typed from memory.


Steve Hodgkiss 7 lessons

One method, one page, one honest capture. That is the shape of this book.

pandas, one method per page

Twenty-four lessons on the pandas methods beginners actually meet: loc, iloc, at, iat; df[mask], isin, query, where; sort_values, reset_index, head, nlargest; dropna, fillna, isna, drop_duplicates; merge, concat, join, assign; groupby, agg, value_counts, one honest hour; every method meaning traced to this box's cached pandas docs pages, and every returned value read whole from a twenty-four line method sweep pandas 3.1.2 on python 3.14.9 ran on this box on the fifth of December, 2026, one call, one return, one mutate check and one surprise per line, nothing typed from memory.


Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).

An honest book about its demo: python 3.14.9 with pandas 3.1.2 on numpy 2.5.4 on the machine that built this book ran a twenty-four line method sweep on 2026-12-05, one call text, one returned value, a before and after mutate check and one surprise case per method, each capture kept whole. The sweep opened no network port and fetched no remote data; the values live in /root/.hermes/cache/web/slot197park/pandas_demo197.txt, and no value was typed from memory. pandas 3 reprs carry the numpy type prefix (np.int64(74)) and are quoted exactly as the file states them; the sweep's chained-assignment line produced no error and changed nothing, warning only on stderr, and that stderr text is kept whole in the file. The sweep's six-row demo frame and the small side frames it ran on are part of the same capture; the sweep file's own stderr tail names the script that built them, and a verified copy lives beside the sweep. All method meaning traces to the 29 cached rendered pandas docs pages (pandas.pydata.org stable docs for pandas 3.1.2, fetched 2026-12-05 with STATUS 200 and size headers recorded). The demand framing is mined from public beginner-thread titles, used as questions only, never as facts. No facts from vendor blogs, search-engine snippets or books. Independent, not affiliated with pandas, NumFOCUS or the NumPy project.

Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.

© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.

Edition 1.0 · stevehodgkiss.net

Contents

Contents


Part 1 · The two indexers
loc4
Part 2 · Rows and masks
df[mask]5
Part 3 · Shape and order
sort_values6
Part 4 · Missing values
dropna7
Part 5 · Combine tables
merge8
Part 6 · Groups and the honest hour9
groupby10
one honest hour11

Per the pandas loc API page, Access a group of rows and columns by label(s) or a boolean array; .loc[] is primarily label based, but may also be used with a boolean array; Note that contrary to usual python slices, both the start and the stop are included; A single label, e.g. 5 or 'a', (note that 5 is interpreted as a label of the index, and never as an integer position along the index). Per the beginner threads digest, loc vs iloc; inclusive vs exclusive slice ends; the single most common pandas error. Per a real capture on the build machine (2026-12-05), call: df.loc[11]; result: {'name': 'ben', 'dept': 'eng', 'age': 41, 'salary': 74}; call: df.loc[11, 'salary'] = 101; result: mutates in place; before: df.loc[11, 'salary'] == 74; after: df.loc[11, 'salary'] == 101; call: df.loc[11:13]; result: [11, 12, 13]; surprise: LABEL slices are INCLUSIVE on both ends; call: df2[df2['dept'] == 'eng']['salary'] = 999; result: no error; salary unchanged: np.int64(90); ChainedAssignmentError: A value is being set on a copy of a DataFrame or Series through chained assignment.; Such chained assignment never works to update the original DataFrame or Series, because the intermediate object on which we are setting values always behaves as a copy (due to Copy-on-Write).; Try using '.loc[row_indexer, col_indexer] = value' instead, to perform the assignment in a single step. Per this book's plan, loc opens the book: the label door that reads, writes in place, and keeps the stop.

pandas companion · No. 01
the label door

loc

rows and cells by label

the label door: read a row, write a cell, keep the stopnamedeptagesalary10adaeng349011beneng417412cuiops296113daraops528814elieng379515fayqa2348df.loc[11:13][11, 12, 13]the label slice keeps the stopdf.loc[11, 'salary'] = 101the one-line writedf.loc[11]{'name': 'ben', 'dept': 'eng', 'age': 41, 'salary': 74}row 11, read wholenp.int64(90)captured: label access, a write in place, and a slice that keeps its stop

loc works by label: it Access a group of rows and columns by label(s) or a boolean array, and the label slice keeps the stop.

Captured: df.loc[11] returned the whole ben row. The chained write df2[df2['dept'] == 'eng']['salary'] = 999 gave no error, left the cell np.int64(90): warned on stderr, changed nothing.

One indexer, three jobs: read by label, write in place, keep the stop.

SPEND ONE HONEST HOUR

This week, read one row with loc, then chain an assignment and watch nothing change.

Per the pandas indexing user guide, Another common operation is the use of boolean vectors to filter the data; The operators are: | for or, & for and, and ~ for not; These must be grouped by using parentheses, since by default Python will evaluate an expression such as df['A'] > 2 & df['B'] < 3 as df['A'] > (2 & df['B']) < 3, while the desired evaluation order is (df['A'] > 2) & (df['B'] < 3). Per the beginner threads digest, Boolean mask grammar; with parentheses around each condition; three meanings for one syntax. Per a real capture on the build machine (2026-12-05), call: df[df['age'] > 30]; result: ['ada', 'ben', 'dara', 'eli']; call: df[(df['dept'] == 'eng') & (df['age'] > 30)]; result: ['ada', 'ben', 'eli']; call: df['dept'] == 'eng' & (df['age'] > 30); result: TypeError: Cannot perform 'rand_' with a dtyped [bool] array and scalar of type [bool]. Per this book's plan, the bare brackets open the filter part: one rule, rows out, and the parentheses the grammar demands.

pandas companion · No. 02
the rule row

df[mask]

rows that pass the rule

rows that pass the rule, one condition per bracketnamedeptagesalary10adaeng349011beneng417412cuiops296113daraops528814elieng379515fayqa2348['ada', 'ben', 'dara', 'eli']no parentheses, no grammar:df['dept'] == 'eng' & (df['age'] > 30)TypeError: Cannot perform 'rand_' with a dtypeddf[df['age'] > 30]['ada', 'ben', 'dara', 'eli']TypeError: Cannot perform 'rand_' with a dtypedcaptured: four rows kept by the rule, the bare grammar broke

df[mask] keeps rows: the guide calls it the use of boolean vectors to filter the data, and the operators are | for or, & for and, and ~ for not.

Captured: df[df['age'] > 30] kept ['ada', 'ben', 'dara', 'eli'] and the combined mask kept ['ada', 'ben', 'eli']. Without parentheses the grammar breaks: TypeError: Cannot perform 'rand_' with a dtyped [bool] array and scalar of type [bool].

One rule per bracket: every condition in its own parentheses.

SPEND ONE HONEST HOUR

This week, mask your own frame twice: once alone, once combined with and.

Per the pandas sort_values API page, Sort by the values along either axis; This method sorts the DataFrame by the values in one or more columns or by index/column labels; ascending bool or list of bool, default True Sort ascending. Per a real capture on the build machine (2026-12-05), call: df.sort_values('salary', ascending=False); result: ['eli', 'ada', 'dara', 'ben', 'cui', 'fay']; surprise: . Per this book's plan, sort_values opens the order part: one column decides, a new frame comes back, and the original keeps its order.

pandas companion · No. 03
the arranger

sort_values

order by a column, new frame

one column decides, a new frame comes backnamedeptagesalary10adaeng349011beneng417412cuiops296113daraops528814elieng379515fayqa2348salary, descendingeli95ada90dara88ben74cui61fay48returns a new framethe original keeps its orderdf.sort_values('salary', ascending=False)['eli', 'ada', 'dara', 'ben', 'cui', 'fay']returns a new frame; the original keeps its ordercaptured: salary sorted descending in a new frame; the original unmoved

sort_values orders: it Sort by the values along either axis, by the values in one or more columns or by index/column labels.

Captured: df.sort_values('salary', ascending=False) returned ['eli', 'ada', 'dara', 'ben', 'cui', 'fay'], and the capture adds the part beginners miss: returns a new frame; the original keeps its order.

A sort you can hold: new frame out, original untouched.

SPEND ONE HONEST HOUR

This week, sort your own frame by one column and print the original after.

Per the pandas dropna API page, Remove missing values; how {'any', 'all'}, default 'any' Determine if row or column is removed from DataFrame, when we have at least one NA or all NA; Drop the rows where at least one element is missing. Per the pandas missing data user guide, dropna() drops rows or columns with missing data. Per a real capture on the build machine (2026-12-05), call: messy.dropna(); result: ['ada', 'ben', 'dara', 'eli', 'fay']; before: NaN cells 1; after: NaN cells 0. Per this book's plan, dropna opens the missing part with the strict door: one NaN in a row and the whole row leaves.

pandas companion · No. 04
the dropper

dropna

rows with a NaN leave

one NaN in a row and the whole row leavesnamedeptagesalary10adaeng349011beneng417412cuiops29nan13daraops528814elieng379515fayqa2348namedeptagesalary10adaeng349011beneng417413daraops528814elieng379515fayqa2348the row that leaves:after: NaN cells 0how='any' is the defaultmessy.dropna()['ada', 'ben', 'dara', 'eli', 'fay']NaN cells 1NaN cells 0captured: five rows kept, one row gone for a single NaN cell

dropna removes: it Remove missing values, and the guide is plain: dropna() drops rows or columns with missing data. The default is any: when we have at least one NA or all NA, the row goes.

Captured: messy.dropna() kept ['ada', 'ben', 'dara', 'eli', 'fay']; NaN cells 1 became NaN cells 0. The trap is the price: a row with one NaN leaves, five good cells ride out with it.

The strict door: one hole, the whole row.

SPEND ONE HONEST HOUR

This week, dropna your own frame and count the rows you lost.

Per the pandas merge API page, Merge DataFrame or named Series objects with a database-style join; The join is done on columns or indexes; If joining columns on columns, the DataFrame indexes will be ignored. Per the pandas merging user guide, For a many-to-many join, if a key combination appears more than once in both tables, the DataFrame will have the Cartesian product of the associated data; The how argument to merge() specifies which keys are included in the resulting table; If a key combination does not appear in either the left or right tables, the values in the joined table will be NA. Per the beginner threads digest, merge row jumps; quietly multiply rows; a left join turns int columns float. Per a real capture on the build machine (2026-12-05), call: df.merge(offices, on='dept'); result: rows 6 -> 9; eng rows doubled because eng appears twice in offices; before: left rows 6; after: merged rows 9; call: df.merge(offices, on='dept', how='left'); result: salary dtype dtype('int64') -> dtype('int64'); surprise: a left join that can add NaN turns int columns float. Per this book's plan, merge opens the combine part with the row-count trap: check the rows before and after, every time.

pandas companion · No. 05
the key stitch

merge

two tables stitched on a key

two tables stitched on dept; a repeated key multiplies rowsnamedeptagesalary10adaeng349011beneng417412cuiops296113daraops528814elieng379515fayqa2348key column: deptdeptofficeengleedsopsleedsengleedsqahulloffices: eng appears twicemerged rows 9dtype('int64')no NaN, no flipdf.merge(offices, on='dept')rows 6 -> 9; eng rows doubled because eng appears twice in officeshow='left'our left capture matched every rowcaptured: nine rows out of six; our left join never met a NaN

merge stitches on a key: it Merge DataFrame or named Series objects with a database-style join.

Captured: df.merge(offices, on='dept') went rows 6 -> 9: the DataFrame will have the Cartesian product of the associated data.

Our left capture matched every row, so the dtype stayed salary dtype dtype('int64') -> dtype('int64'): a left join that can add NaN turns int columns float.

Stitch, then count: the row count is the receipt.

SPEND ONE HONEST HOUR

This week, merge two of your tables and compare the row counts.

Part 6 of 6
groupby, agg, value_counts, one honest hour
6

Groups and the honest hour

Per the pandas groupby API page, Group DataFrame using a mapper or by a Series of columns; A groupby operation involves some combination of splitting the object, applying a function, and combining the results. Per the pandas groupby user guide, Aggregation: compute a summary statistic (or statistics) for each group. Per the pandas aggregate API page, Aggregate using one or more operations over the specified axis; This method allows combining multiple aggregation functions at once, such as sum, mean, and min. Per the beginner threads digest, groupby shape surprise; returns a Series; returns a DataFrame. Per a real capture on the build machine (2026-12-05), call: df.groupby('dept')['salary'].mean() vs df.groupby('dept')[['salary']].mean(); result: single bracket -> Series; double bracket -> DataFrame; index ['eng', 'ops', 'qa']; call: df.groupby('dept').agg(n=('salary','size'), avg=('salary','mean')); result: {'eng': 86.3, 'ops': 74.5, 'qa': 48.0}. Per this book's plan, groups close the book: the split-apply-combine funnel, the named reductions, the counts, then the closer that asks for an hour of the reader's own, one method per goal, the shape check in their hands.


In this part
  1. 01groupby
  2. 02one honest hour

Per the pandas groupby API page, Group DataFrame using a mapper or by a Series of columns; A groupby operation involves some combination of splitting the object, applying a function, and combining the results. Per the pandas groupby user guide, Splitting the data into groups based on some criteria. Applying a function to each group independently. Combining the results into a data structure. Per the beginner threads digest, groupby shape surprise; returns a Series; returns a DataFrame. Per a real capture on the build machine (2026-12-05), call: df.groupby('dept')['salary'].mean() vs df.groupby('dept')[['salary']].mean(); result: single bracket -> Series; double bracket -> DataFrame; index ['eng', 'ops', 'qa']. Per this book's plan, groupby opens the last part with the shape surprise: the brackets decide what shape comes back.

pandas companion · No. 06
the splitter

groupby

split, apply, combine

split, apply, combine: the shape surprisedf.groupby('dept')['salary'].mean()eng: 3adabeneli86.3ops: 2cuidara74.5qa: 1fay48.0single bracket -> Seriesdouble bracket -> DataFrameindex ['eng', 'ops', 'qa']single bracket -> Seriesdouble bracket -> DataFrameone bracket apart, two shapescaptured: three groups split, one mean each, and the brackets chose the shape

groupby splits: it Group DataFrame using a mapper or by a Series of columns, some combination of splitting the object, applying a function, and combining the results.

Captured: one bracket gave single bracket -> Series, two gave double bracket -> DataFrame, the group index ['eng', 'ops', 'qa']. Same call, one bracket apart, two shapes.

The shape surprise: one bracket a Series, two a DataFrame.

SPEND ONE HONEST HOUR

This week, groupby your own column both ways and print the type of each answer.

Per this book's plan, the closer labels itself: one honest hour on your own frame, one method per goal without searching, then the shape check the hour keeps; the reader picks loc or iloc to read, a mask to filter, a groupby to summarize, and runs the Series-versus-DataFrame check after each pick. Per the beginner threads digest, groupby shape surprise; returns a Series. Per a real capture on the build machine (2026-12-05), call: df.groupby('dept')['salary'].mean(); result: type Series; before: the shape line the reader checks after picking their own method. Per this book's plan, the hour is the point of the book: no capture of ours beyond the shape check the hour itself runs.

pandas companion · No. 07
the closer

one honest hour

your frame, one method per goal

one frame of your own, one method per goalreplopen your own framepick one method per goalno search, no frameworkrun the shape checkthis book's plan:one method per goal,then the shape check:groupby('dept')['salary']type Seriesno project, no prices, one capture: the hour closes one method at a time

Nothing new for once, a plan. Per this book's plan: open your own frame, and pick one method per goal without searching. Read with loc or iloc, filter with a mask, order with sort_values, fill what is missing, combine two tables, group what repeats.

Then run the shape check the hour keeps: call your grouped mean and read what type comes back. On this box the check returned type Series: one bracket, one Series. If a DataFrame appears, the brackets doubled.

One method, one page, one honest capture: the hour is yours now.

SPEND ONE HONEST HOUR

This week, spend sixty honest minutes with your own frame: one method per goal.

Index

Index


df[mask]5
dropna7
groupby10
loc4
merge8
one honest hour11
sort_values6