Pandas/Selecting rows 7 min

Filtering and sorting

Boolean masks, loc and sort_values.

masklocsort_values

A comparison on a column produces a boolean Series. Passing it back into the frame keeps the rows where it is True.

python · editable
loading editor…

Combine conditions with & and | — each condition needs its own brackets. .isin() matches a list of values and ~ negates a mask.

python · editable
loading editor…

Use .loc for label-based selection of rows and columns at once, and sort_values to order the result.

python · editable
loading editor…