Series#
pandas.Series is a 1-D labelled array: a fixed-length
homogeneous-dtype sequence with an explicit index (the labels)
alongside the values. Third-party (pip install pandas), not
in the standard library. Reach for it whenever the operator
wants a numpy array with named positions, time-series alignment,
or row-of-a-dataframe semantics.
Construct from a list; the index defaults to 0..n-1.
import pandas as pd
s = pd.Series([10, 20, 30])
Construct with an explicit index.
s = pd.Series([10, 20, 30], index=["a", "b", "c"], name="latency_ms")
Construct from a dict; the keys become the index.
s = pd.Series({"alice": 30, "bob": 25, "carol": 41})
Label-based access with .loc.
s.loc["b"]
Positional access with .iloc.
s.iloc[0]
Vectorised arithmetic broadcasts over the values.
s * 2
Boolean indexing filters by mask.
s[s > 100]
Aggregations are one-liners.
s.sum(), s.mean(), s.median(), s.std(), s.quantile(0.95)
Alignment is automatic on operations between two Series with
overlapping but unequal indexes; missing labels become NaN.
a + b
Method catalog#
The most-used surface.
Method |
Effect |
|---|---|
|
First |
|
Last |
|
Summary statistics (count, mean, std, min, quantiles, max). |
|
Distinct values, in order of first appearance. |
|
Frequency table, descending. |
|
Sort by value. |
|
Sort by label. |
|
Element-wise transform. |
|
Same, with reduce semantics on a DataFrame. |
|
Drop missing values. |
|
Replace missing values with |
|
Boolean mask of missing / present values. |
|
Cast every element to a dtype. |
|
Rolling-window aggregation. |
|
Promote to a single-column |
|
Underlying numpy array. |
|
Plain Python list. |