Creating a Series
🎬 This topic has a 4:45 video: The Series: Five Ways to Make One →A Series can be born from all sorts of data — a plain list, a NumPy array, a dictionary, even a single value. Every one of them starts with the same import, then a call to pd.Series(...).
Play with the builder below to preview each source, then run the real code in the panels underneath.
Pick a source of data — see the code that builds it and the Series it produces.
import pandas as pd cities = ['Mumbai', 'Delhi', 'Bengaluru', 'Chennai'] s = pd.Series(cities) print(s)
💡 List: Most common way. Pandas auto-numbers the index from 0.
1Method 1 — The empty Series
Sometimes you need to start with nothing and fill it in later. Calling pd.Series() with no arguments creates an empty Series.
2Method 2 — From a Python list
This is the most common way. Pandas automatically creates a default integer index starting from 0.
Beyond the default: pass index=... to give every value a meaningful label of your own.
index list must be the same length as the data list — one label per value.3Method 3 — From a NumPy ndarray
Pandas is built on top of NumPy, so turning an array into a Series is seamless and efficient.
4Method 4 — From a dictionary
This one is powerful: the dictionary's keys automatically become the Series' index labels, and the values become the data.
5Method 5 — From a scalar (single value)
Want a Series where every element is the same? Give a single value and an index. Pandas repeats the value once for every label.
The index does double duty here: it sets both the labels and the length. Three labels give three copies.
What if you leave the index out? There is no error. You get a Series with just one value, at the default label 0:
index is not an error. It is a Series of length 1. To repeat the value, you need the index.6Practice — find the errors
Board papers often give a short Pandas program with mistakes in it and ask you to rewrite the correct code and underline the corrections. Here are two of them.
One thing to know first: Python stops at the first mistake it finds. So run the program, fix that mistake, and run it again. The next mistake then shows itself.
Error hunt 1 (2025 board paper)
Rohit wants a Series of three numbers with the labels x, y and z. Run his program and read the error.
Fix one mistake at a time, and this is what Python says after each run:
| Run | Python stops with | The fix |
|---|---|---|
| 1 | NameError: name 'pd' is not defined | import pandas as pd |
| 2 | AttributeError: module 'pandas' has no attribute 'series' | Series, with a capital S |
| 3 | TypeError: ... got an unexpected keyword argument 'Index' | index, in small letters |
| 4 | NameError: name 'Print' is not defined | print, in small letters |
Four corrections. The correct program and its output:
import pandas as pd
data = [50, 15, 40]
series = pd.Series(data, index=['x', 'y', 'z'])
print(series)x 50 y 15 z 40 dtype: int64
Error hunt 2 (2024 board paper)
This program should make a Series from a student's details. Run it.
This time Python does not even start running. Line 2 is a SyntaxError: key:value pairs belong inside curly brackets, so it must be a dictionary. Fix that, and the other mistakes appear one by one:
| Run | Python stops with | The fix |
|---|---|---|
| 1 | SyntaxError: invalid syntax (line 2) | { } instead of [ ]: a dictionary |
| 2 | ModuleNotFoundError: No module named 'Pandas' | import pandas, in small letters |
| 3 | NameError: name 'p' is not defined | pd.Series, the alias is pd |
| 4 | NameError: name 's' is not defined | pd.Series(stud): pass the dictionary |
import pandas as pd
stud={'Name':'Ramya','Class':11,'House':'Red'}
s=pd.Series(stud)
print(s)Name Ramya Class 11 House Red dtype: object
as pd, Series without its capital S, a capital letter in index or print, square brackets where a dictionary needs curly ones, and a variable name that was never made.7Recap — five ways in
| Source | Example | Index you get |
|---|---|---|
| Empty | pd.Series() | none (empty) |
| List | pd.Series([1, 2, 3]) | default 0, 1, 2 |
| List + index | pd.Series(data, index=labels) | your labels |
| NumPy array | pd.Series(np.array([...])) | default 0, 1, 2 |
| Dictionary | pd.Series({'a': 1}) | the dict keys |
| Scalar | pd.Series(9, index=[...]) | your labels (one copy each) |
You build a Series from a dictionary. What becomes the index?
What does pd.Series(9) give, with no index?