The Series: Pandas
Reviewed & published by Brayan K
A Pandas Series is a one-dimensional labelled array — a single column of data where every value is paired with an index label, like a smarter, faster version of a Python list.
Part of the free Pandas course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
The Series is the foundation of everything in Pandas: every column of a DataFrame is a Series. Master it here and the DataFrame will feel natural.
What You'll Learn in This Lesson
- Create a Series from a list and from a dictionary
- Understand the index and how labels work
- Access values by label and by position
- Inspect s.values, s.index, and s.dtype
- Do vectorised math like s * 2
- Filter a Series with boolean indexing
1 Creating a Series from a List
The simplest way to make a Series is to pass a Python list to pd.Series(). Pandas adds a default integer index (0, 1, 2, ...) and infers a single dtype for all the values.
s = pd.Series([10, 20, 30, 40])Printing a Series shows two columns: the index on the left and the values on the right, with the dtype noted at the bottom.
import pandas as pd
# A Series from a plain list — Pandas adds the index automatically
s = pd.Series([10, 20, 30, 40])
print(s)
# Output:
# 0 10
# 1 20
# 2 30
# 3 40
# dtype: int64
# ✅ Expected output:
# 0 10
# 1 20
# 2 30
# 3 40
# dtype: int642 The Index — Custom Labels and Dictionaries
The index is what makes a Series special. Instead of bare positions, you can give each value a meaningful label:
s = pd.Series([85, 92, 78], index=["math", "english", "science"])If you build a Series from a dictionary, the keys become the index labels and the values become the data — automatically:
scores = {"math": 85, "english": 92, "science": 78}
s = pd.Series(scores)import pandas as pd
# Build a Series from a dictionary — keys become the index
scores = {"math": 85, "english": 92, "science": 78}
s = pd.Series(scores)
print(s)
# Output:
# math 85
# english 92
# science 78
# dtype: int64
# ✅ Expected output:
# math 85
# english 92
# science 78
# dtype: int643 Accessing Values and Inspecting a Series
You can pull values out of a Series two ways — by label or by position:
- s["math"] — look up by label (like a dictionary)
- s.iloc[0] — look up by integer position (always position-based)
And three handy attributes describe the Series itself:
- s.values — the underlying NumPy array of values
- s.index — the labels
- s.dtype — the data type of the values
import pandas as pd
scores = pd.Series({"math": 85, "english": 92, "science": 78})
print(scores["math"]) # by label
print(scores.iloc[0]) # by position
print(scores.values) # the raw values
print(scores.index) # the labels
print(scores.dtype) # the data type
# Output:
# 85
# 85
# [85 92 78]
# Index(['math', 'english', 'science'], dtype='object')
# int64
# ✅ Expected output:
# 85
# 85
# [85 92 78]
# Index(['math', 'english', 'science'], dtype='object')
# int644 Vectorised Math and Boolean Indexing
Because a Series is backed by NumPy, math applies to every element at once — no loop needed. This is called a vectorised operation:
s = pd.Series([10, 20, 30])
s * 2 # → 20, 40, 60 (every value doubled)You can also keep only the values that match a condition. A comparison like s > 20 produces a Series of True/False, and feeding that back into s[...] keeps only the True rows — this is boolean indexing:
s[s > 20] # keep only values greater than 20import pandas as pd
s = pd.Series([10, 20, 30, 40])
# Vectorised math — applies to every element
print(s * 2)
# Boolean indexing — keep only values greater than 20
print(s[s > 20])
# Output:
# 0 20
# 1 40
# 2 60
# 3 80
# dtype: int64
# 2 30
# 3 40
# dtype: int64
# ✅ Expected output:
# 0 20
# 1 40
# 2 60
# 3 80
# dtype: int64
# 2 30
# 3 40
# dtype: int64import pandas as pd
prices = pd.Series([5, 12, 8, 20, 3])
# 🎯 YOUR TURN: keep only the prices greater than 10
# Replace ___ with the correct comparison
expensive = prices[prices ___ 10]
print(expensive)
# Expected output:
# 1 12
# 3 20
# dtype: int64! Common Errors (And How to Fix Them)
Looking up a label that doesn't exist:
s = pd.Series({"math": 85})
s["maths"] # ❌ KeyError: 'maths' (typo!)✅ Fix: match the label exactly, or check with s.index.
❌ Position vs label confusion
With a custom index, s[0] may be ambiguous.
✅ Fix: use s.iloc[0] for position and s.loc["label"] for labels — explicit is safer.
🎯 Mini Challenge: Temperature Conversion
Use a Series and vectorised math to convert Celsius to Fahrenheit:
- Make a Series of Celsius temperatures
- Apply the formula C * 9/5 + 32 to the whole Series at once
- Print the Fahrenheit results
import pandas as pd
celsius = pd.Series([0, 20, 37, 100])
# Vectorised conversion — applies to every value at once
fahrenheit = celsius * 9 / 5 + 32
print(fahrenheit)
# Output:
# 0 32.0
# 1 68.0
# 2 98.6
# 3 212.0
# dtype: float64
# ✅ Expected output:
# 0 32.0
# 1 68.0
# 2 98.6
# 3 212.0
# dtype: float64❓ Frequently Asked Questions
Lesson complete — you've met the Series!
You can create a Series from lists and dicts, work with the index, access values by label and position, do vectorised math, and filter with boolean masks.
Practice quiz
A pandas Series is best described as what?
- A one-dimensional labeled array
- A two-dimensional table
- A dictionary of frames
- An immutable tuple
Answer: A one-dimensional labeled array. A Series is a 1-D array with an index of labels.
How do you create a Series from the list [1, 2, 3]?
- pd.Frame([1,2,3])
- pd.Series([1, 2, 3])
- pd.Array([1,2,3])
- pd.List([1,2,3])
Answer: pd.Series([1, 2, 3]). pd.Series([1, 2, 3]) builds a Series from the list.
When you build a Series from a dict, what becomes the index?
- Integers 0,1,2
- The values
- The dict's keys
- Nothing
Answer: The dict's keys. Dict keys become the Series index and values become the data.
Given s = pd.Series([10,20,30], index=['a','b','c']), what is s['a']?
- 20
- 'a'
- 30
- 10
Answer: 10. Label 'a' maps to the first value, 10.
What is the default index for pd.Series([1, 2, 3])?
- 0, 1, 2
- 1, 2, 3
- a, b, c
- The values themselves
Answer: 0, 1, 2. Without an index argument, pandas uses a RangeIndex 0,1,2.
How do you access a Series element by integer POSITION?
- s.loc[0]
- s.iloc[0]
- s.pos[0]
- s.get_position(0)
Answer: s.iloc[0]. iloc is position-based, so s.iloc[0] returns the first value.
What does pd.Series([1, 2, 3]) * 2 produce?
- [1, 2, 3, 1, 2, 3]
- An error
- [2, 4, 6]
- [1, 2, 3]
Answer: [2, 4, 6]. Arithmetic on a Series is vectorised: each element doubles.
How do you keep only Series values greater than 1?
- s.filter(>1)
- s.where_gt(1)
- s.keep(1)
- s[s > 1]
Answer: s[s > 1]. A boolean mask s[s > 1] keeps elements where the condition is True.
What is the dtype of pd.Series([1, 2, 3])?
- int64
- object
- float64
- str
Answer: int64. A Series of whole numbers gets the int64 dtype.
Which attribute returns the underlying NumPy array of a Series?
- s.array_data
- s.values
- s.numpy
- s.raw
Answer: s.values. s.values returns the data as a NumPy ndarray.
Continue this course
- Previous: Introduction to Pandas
- Next: The DataFrame: Rows and Columns — Understand the DataFrame — Pandas' core 2-D table of rows and columns
- Quick reference: Pandas cheat sheet › Creating & Loading
Frequently asked questions
What is a Pandas Series?
A Series is a one-dimensional labelled array — a single column of data where every value has an associated index label. It is the building block of the DataFrame: each DataFrame column is a Series.
How is a Series different from a Python list?
A list is just an ordered sequence of values. A Series adds a labelled index, a fixed data type (dtype), and vectorised operations — so s * 2 doubles every element at once, and you can look values up by label, not just by position.
What is the index of a Series?
The index is the set of labels attached to the values. By default it is integers 0, 1, 2, ..., but you can set any labels you like (such as names or dates). You access it with s.index.
How do I get the values out of a Series?
Use s.values to get the underlying NumPy array of values, s.index for the labels, and s.dtype to see the data type. You can select a single value by label with s['label'] or by position with s.iloc[0].