Labeled one-dimensional data
Represent a single labeled variable such as scores, measurements, or categories.
Pandas · Class
pandas.Series is a one-dimensional labeled data structure that supports positional and label-based indexing. Arithmetic aligns operands by their index labels.
Series stores one-dimensional data together with an index and optional name. It supports label-based and integer-based access, while arithmetic with another Series matches values by index and produces the sorted union of their indexes.
class pandas.Series(*data=None*, *index=None*, *dtype=None*, *name=None*, *copy=None*)[source]| Name | Type | Description |
|---|---|---|
data | array-like, Iterable, dict, or scalar value | Array-like, Iterable, dict, or scalar value containing the Series data. |
index | array-like or Index | Array-like or Index labels; labels must be hashable and match the data length. |
dtype | str, numpy.dtype, or ExtensionDtype, optional | Output data type; inferred from data when omitted. |
name | Hashable, default None | Name assigned to the Series. |
copy | bool, default None | Whether to copy the input data. |
A pandas Series object containing the supplied data, index, dtype, and name.
import pandas as pd
s = pd.Series([10, 20, 30], index=["a", "b", "c"], name="scores")
print(s.loc["b"])
print((s + pd.Series([1, 2], index=["b", "c"])).dropna())Creates a labeled Series, selects by label, and demonstrates index-aligned arithmetic.
Represent a single labeled variable such as scores, measurements, or categories.
Work with timestamps and indexed observations in a time-series workflow.
Combine or compare labeled values from different sources while preserving label correspondence.
Series is a one-dimensional ndarray-like object with axis labels. It supports both integer-based and label-based indexing and includes methods for operations involving its index.
Follow-up: How does Series arithmetic handle different indexes? It aligns operands by their associated index values rather than by array position.
The data argument supplies the stored values and may be array-like, iterable, a dictionary, or a scalar. The index argument supplies labels; without one, pandas uses a RangeIndex.
Follow-up: What constraint applies to an explicit index? Its values must be hashable and have the same length as the data.
Series operations such as addition align values using their associated indexes, even when the operands have different lengths. The output index is the sorted union of both input indexes.
Follow-up: What should be checked after alignment? Labels missing from either operand can produce missing results, so inspect or handle those values explicitly.
pandas.DataFramepandas.IndexSeries.locSeries.ilocSeries.itemsSeries.resample