Series

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

head(n=5)

First n rows.

tail(n=5)

Last n rows.

describe()

Summary statistics (count, mean, std, min, quantiles, max).

unique()

Distinct values, in order of first appearance.

value_counts()

Frequency table, descending.

sort_values(*, ascending=True)

Sort by value.

sort_index()

Sort by label.

map(f)

Element-wise transform.

apply(f)

Same, with reduce semantics on a DataFrame.

dropna()

Drop missing values.

fillna(v)

Replace missing values with v (or a method).

isna() / notna()

Boolean mask of missing / present values.

astype(dtype)

Cast every element to a dtype.

rolling(window).mean()

Rolling-window aggregation.

to_frame()

Promote to a single-column DataFrame.

to_numpy()

Underlying numpy array.

to_list()

Plain Python list.

References#

  • DataFrame for the 2-D tabular sibling.

  • list for the one-allocation Python list these structures replace at scale.

  • pandas.Series.