1. Introduction to pandas
1.2 Series: one labelled column
Highlights & notes
Select lesson text to highlight it, or tap Add note.
Bookmarks
Bookmark a lesson to see it here.
A Series holds values in order, each with a label called the index. By default the labels are 0, 1, 2 …, just like list positions.
s = pd.Series([250, 400, 150])creates the Seriess[0]reads the value with label 0s.sum(),s.mean()ands.max()summarise the whole columns * 2doubles every value at once, with no loop
You can choose your own labels: pd.Series([250, 400], index=["mon", "tue"]), then read s["tue"].
List vs Series
[250, 400, 150] * 2→ repeats the list: 6 itemspd.Series([250, 400, 150]) * 2→ doubles each value: 500, 800, 300
Maths on a Series works on every value at once. This is called vectorised work, and it’s why pandas is fast on big data.
How it fits together
- mon · 250
- tue · 400
- wed · 150
Step through the code
Python
import pandas as pdsales = pd.Series([250, 400, 150], index=["mon", "tue", "wed"])print(sales["tue"])print(sales.sum())print(sales * 2)
Output
400 800 mon 500 tue 800 wed 300 dtype: int64
Practice in pandas ✓ Solved
Create a Series marks with 60, 75 and 90, then print the mean.
Expected output
75.0
Reference solution
import pandas as pd
marks = pd.Series([60, 75, 90])
print(marks.mean())
Question 1 · Easy
s = pd.Series([3, 5, 7]). What is s[0]?
Question 2 · Medium
s = pd.Series([10, 20, 30]). What does s.sum() give?
Question 3 · Hard
s = pd.Series([1, 2, 3]). What does (s * 2).tolist() give?
Key takeaways
A Series is one column of values with labels. Maths and summaries like sum() and mean() work on the whole column at once.
Save your progress
Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.
Start free Log in