Series Basics
A pandas Series is a one-dimensional, labeled array capable of holding any single data type — integers, floats, strings, booleans, datetimes, or arbitrary Python objects. Every Series has two essential parts: the values, a NumPy array (or an extension array for special dtypes) holding the actual data, and the index, a separate array of labels that identifies each entry. Unlike a plain Python list, a Series lets you look up elements by meaningful label instead of only by integer position, and it inherits NumPy's fast, vectorized arithmetic, so operations like series * 2 run without an explicit Python loop.
Cricket analogy: A pandas Series holding a batter's scores is like a scorecard column labeled by innings number, where the underlying NumPy array stores the runs and the index labels which innings each score belongs to, letting scores * 1.0 compute strike-adjusted values instantly across all innings.
Creating a Series
A Series can be constructed from a list, a NumPy array, a dictionary, or a scalar. When you pass a dictionary, the keys automatically become the index. If you don't supply an index explicitly, pandas assigns a default RangeIndex starting at 0. You can also give a Series a name, which becomes useful later when the Series is inserted into a DataFrame as a named column.
Cricket analogy: Building a Series from a dict like {'Kohli': 82, 'Rohit': 65} automatically makes the player names the index, while building it from a plain list of scores gives a default RangeIndex, and naming the Series 'innings_1_runs' makes it self-documenting later.
import pandas as pd
s1 = pd.Series([10, 20, 30], index=['a', 'b', 'c'], name='scores')
print(s1)
# a 10
# b 20
# c 30
# Name: scores, dtype: int64
s2 = pd.Series({'NY': 8.3, 'LA': 3.9, 'SF': 0.87}) # dict -> index is keys
print(s2['LA']) # 3.9 (label-based lookup)
print(s1 + 5) # vectorized: adds 5 to every element, index preserved
Index Alignment in Arithmetic
When you perform arithmetic between two Series, pandas aligns them by index label before computing, not by their raw positional order. If a label exists in one Series but not the other, the result contains NaN at that position rather than raising an error or silently dropping the row. This automatic alignment is a defining feature that distinguishes Series math from plain NumPy array math, and it means the order in which you constructed two Series does not matter as long as the labels line up conceptually.
Cricket analogy: Adding a Series of Kohli's runs indexed by match_id to a Series of Rohit's runs indexed by match_id aligns them match-by-match, producing NaN for any match one player didn't play, regardless of which player's data was constructed first.
import pandas as pd
revenue = pd.Series({'Jan': 100, 'Feb': 150, 'Mar': 120})
costs = pd.Series({'Feb': 90, 'Mar': 80, 'Apr': 60})
profit = revenue - costs
print(profit)
# Apr NaN (only in costs)
# Feb 60.0
# Jan NaN (only in revenue)
# Mar 40.0
# dtype: float64
Think of a Series as a hybrid of a Python dict and a NumPy array: like a dict, it supports fast label-based lookup; like an array, it supports vectorized math, broadcasting, and slicing — and both interfaces work on the same object simultaneously.
Because arithmetic between misaligned Series introduces NaN wherever labels don't match on both sides, forgetting to check for NaN afterward (e.g. with .isna().sum()) can silently propagate missing values into later calculations.
- A Series has two core components:
values(a NumPy/extension array) andindex(the labels). - Constructing a Series from a dict uses the dict's keys as the index automatically.
- Series support both label-based lookup (like a dict) and vectorized arithmetic (like a NumPy array).
- Arithmetic between two Series aligns by index label, introducing NaN for labels present in only one Series.
- A Series can have a
name, which becomes the column name when inserted into a DataFrame. - Without an explicit index, pandas assigns a default RangeIndex starting from 0.
Practice what you learned
1. What becomes the index when you create a Series from a Python dictionary?
2. When adding two Series with only partially overlapping index labels, what happens at labels present in only one Series?
3. Which two attributes together fully describe the contents of a Series?
4. What index does pandas assign by default if you construct a Series from a plain list without specifying one?
5. What is the purpose of the `name` attribute on a Series?
Was this page helpful?
You May Also Like
What Is Pandas?
An introduction to pandas, the Python library built on NumPy for labeled, tabular data manipulation, covering its core data structures and why it dominates real-world data analysis.
DataFrame Basics
Understand the structure of a pandas DataFrame — rows, columns, index, and dtypes — and the core operations for creating, inspecting, and selecting from tabular data.
Indexing with loc and iloc
Master the two primary pandas selection accessors — .loc for label-based indexing and .iloc for integer-position-based indexing — and the pitfalls of chained indexing.
Handling Missing Data in Pandas
Learn how pandas represents missing values with NaN and NA, and the core toolkit — isna, dropna, fillna, interpolate — for detecting and handling them.