pandas Series
A Series is a one-dimensional labeled array with one dtype. It can be created independently or selected from a DataFrame. With unique column names, df["minutes"] returns a Series and df[["minutes"]] returns a one-column DataFrame. Both support arithmetic; the Series also offers the .str accessor for string operations. One dtype does not mean every value has the same Python type: object dtype can contain mixed objects.
Column operations express a rule across values. Comparisons can produce boolean masks, arithmetic can produce new values, and reductions such as mean collapse the input to a scalar. Many numeric operations use compiled kernels, but storage and performance depend on dtype and operation. A column API alone does not guarantee contiguous storage or a speed improvement.
The index is what surprises people. Two Series combine by matching labels, not by matching positions, so adding a Series indexed 0, 1, 2 to one indexed 2, 1, 0 pairs each label with itself and produces a result that looks shuffled. When a Series comes out of a filter or a group, its labels are whatever survived, and assigning it into another table aligns on those labels. Reset the index deliberately when position is what you actually mean.
By default, mean() skips missing values and divides by the present count; count() counts present values and len() counts all rows. NaN comparisons are operator-dependent: >= is False but != is True. Nullable dtypes may propagate pd.NA into the mask, whose NA entries are excluded when selecting rows. Report missing counts explicitly with isna().
References: pandas Series API, pandas missing data. See it in use in Pandas Foundations: Tables, Filtering, Grouping, and Joins.
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
