PY-401 ยท pandas basics
pandas Series
โฑ 9 min ๐ Real Python 3 ๐ฌ Animated โ Completed
โก The 30-second answer
A pandas Series is a single column of values where every value has a label, called the index. It works like a NumPy array, so sales.mean() and sales > 100 run on every value, but you can also read a value by its label, such as sales["Tue"]. Every column of a pandas table is a Series.
- Create a Series with an index
- Read a value by its label
- Do maths and filter like an array
Try it
Watch it come alive, run it yourself, then prove it. Real Python, right on this page.
Watch Python run the example. Every variable is a jar; watch the values change and the output appear.
import pandas as pdsales = pd.Series([120, 340, 95, 410], index=["Mon", "Tue", "Wed", "Thu"])print(sales)print(sales["Tue"])print(sales.mean())print(sales[sales > 100].index.tolist())
Change anything and press Run (or Ctrl+Enter). Then open Watch it and press Watch my code.
Input one line per input() call
Press Run to see the output. Python runs in your browser. Expected output
Mon 120
Tue 340
Wed 95
Thu 410
dtype: int64
340
241.25
['Mon', 'Tue', 'Thu'] ๐ฏ Make a Series called temps with the values 31, 35, 28 and the labels "Delhi", "Chennai", "Shimla". Then print the temperature in Chennai.
Input one line per input() call
Press Run to see the output. Python runs in your browser. Need a hint?
temps = pd.Series([31, 35, 28], index=["Delhi", "Chennai", "Shimla"]) then print(temps["Chennai"])
- The problemA cafรฉ owner writes daily sales on a whiteboard: Mon 120, Tue 340, Wed 95. A NumPy array would keep the numbers but lose the day names. A Series keeps both.
- The Python idea
import pandas as pdA pandas Series is a single column of values where every value has a label, called the index. - In real lifeA stock app keeps a share price as a Series indexed by date, so "the price on 3 March" is
prices["2026-03-03"]and a 7-day average is one call.
Start with a question
A cafรฉ owner writes daily sales on a whiteboard: Mon 120, Tue 340, Wed 95. A NumPy array would keep the numbers but lose the day names. A Series keeps both.
Real data has names attached: dates, products, customers. A Series keeps the name next to the number, so results stay readable.
Explain it like I'm 10
A Series is a row of lockers. Each locker has a name tag on the door (the index) and something inside (the value). You can open a locker by its name instead of counting.
The technical explanation
Start with import pandas as pd. pandas is built on NumPy, so the maths you learned in module 1 works the same way.
pd.Series([120, 340], index=["Mon", "Tue"]) makes a Series. Without index=, the labels are 0, 1, 2 and so on.
Printing a Series shows the labels on the left, the values on the right and the dtype at the bottom.
sales.mean(), sales * 1.1 and sales[sales > 100] behave like a NumPy array, and the labels travel with the values.
Syntax
import pandas as pd
s = pd.Series(values, index=labels)
s["label"] # by label
s.iloc[0] # by position
s[s > 100] # filter Real-world scenario
A stock app keeps a share price as a Series indexed by date, so "the price on 3 March" is prices["2026-03-03"] and a 7-day average is one call.
Test yourself
5 questions. Get 4 right and this lesson is marked complete.
Pass the quiz to complete this lesson.
๐ Every lesson counts toward your certificate Next: pandas DataFrames โQuestions people ask
What is the difference between a pandas Series and a DataFrame?
A Series is one column of values with an index. A DataFrame is a table of several Series that share the same index, one Series per column.
What is the difference between a Series and a Python dictionary?
Both map labels to values, but a Series keeps its labels in order, holds one type of value and supports vectorised maths and filtering like s > 100, which a dictionary does not.
Interview questions
How this topic comes up in Python interviews. Answer out loud first, then open the model answer.
beginner What is the difference between a pandas Series and a DataFrame?
A Series is one column of values with an index. A DataFrame is a table of several Series that share the same index, one Series per column.
beginner What is the difference between a Series and a Python dictionary?
Both map labels to values, but a Series keeps its labels in order, holds one type of value and supports vectorised maths and filtering like s > 100, which a dictionary does not.
intermediate What does a Series add on top of a NumPy array?
A label for every value. The index gives every value a label.
intermediate s = pd.Series([5, 8], index=["a", "b"]). What is s["b"]?
8. Square brackets with a label read that value.
Quick revision
Remember
- Create a Series with an index
- Read a value by its label
- Do maths and filter like an array
sales[0]on a Series with text labels is confusing and now warns. Usesales["Mon"]for labels andsales.iloc[0]for positions.
Syntax
import pandas as pd
s = pd.Series(values, index=labels)
s["label"] # by label
s.iloc[0] # by position
s[s > 100] # filter Official documentation
- Intro to data structures: Series (docs.python.org)