Series (Pandas)

A Series is pandas' one-dimensional labeled array — a single column of values paired with an index. It is the building block that DataFrame columns are made of.

Pandas

A Series pairs a one-dimensional array of values with an Index. Its storage can be a NumPy array or a Pandas extension array, such as the nullable IntegerArray used by Int64. Arithmetic aligns Series by labels; unmatched labels normally produce missing results.

A Series has one dtype, but that does not mean every stored Python object has the same type: an object Series can contain an integer and a string. Selecting one uniquely named DataFrame column returns a Series; duplicate column labels can make the same bracket selection return a DataFrame.

Use s.iloc[0] for a position and s.loc[label] for a label. Preserve the index when combining labeled data, and choose a dtype deliberately when empty or missing values would otherwise change inference.

Syntax

pd.Series(data, index=None, dtype=None, name=None)

Examples

Python

import pandas as pd
values = pd.Series([10, None, 30], index=["a", "b", "c"], dtype="Int64")
print(values.dtype)
print(type(values.array).__name__)
print(values.isna().tolist())
print(values.dropna().tolist())

Output:

Int64
IntegerArray
[False, True, False]
[10, 30]

Learn it in a lesson

See also

Back to the Dictionary