Last updated
Pandas Series
Definition: A Series is a one-dimensional labelled array — think of it as a single column with an index. It is the building block of a DataFrame.
Example 1 — a simple Series
import pandas as pd s = pd.Series([10, 20, 30, 40]) print(s) print(s[0]) # 10 (by position) print(s.sum()) # 100
The numbers on the left (0,1,2,3) are the index — labels for each value.
Example 2 — custom labels
import pandas as pd s = pd.Series([85, 90, 78], index=["maths", "science", "english"]) print(s) print(s["science"]) # 90 (by label)
Example 3 — from a dictionary
import pandas as pd
prices = pd.Series({"pen": 2, "book": 8, "bag": 25})
print(prices)
print(prices["book"])
💡 Tip: a Series gives you NumPy speed plus meaningful labels — the best of both worlds.
Try it Yourself
Output
Ad · responsive