LambdaLabTM
Informatics Practices · Class 12 · Python Pandas · Series
PandasSeries⏱️ 9 min read

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.

Series builder

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)
0Mumbai
1Delhi
2Bengaluru
3Chennai
dtype: object

💡 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.

method1_empty.py

2Method 2 — From a Python list

This is the most common way. Pandas automatically creates a default integer index starting from 0.

method2_list.py

Beyond the default: pass index=... to give every value a meaningful label of your own.

method2_custom_index.py
Note
The 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.

method3_ndarray.py

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.

method4_dict.py

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.

method5_scalar.py

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:

scalar_no_index.py
Watch Out
So a scalar with no 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.

rohit_series.py

Fix one mistake at a time, and this is what Python says after each run:

RunPython stops withThe fix
1NameError: name 'pd' is not definedimport pandas as pd
2AttributeError: module 'pandas' has no attribute 'series'Series, with a capital S
3TypeError: ... got an unexpected keyword argument 'Index'index, in small letters
4NameError: name 'Print' is not definedprint, in small letters

Four corrections. The correct program and its output:

rohit_series.py
import pandas as pd
data = [50, 15, 40]
series = pd.Series(data, index=['x', 'y', 'z'])
print(series)
Output
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.

student_series.py

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:

RunPython stops withThe fix
1SyntaxError: invalid syntax (line 2){ } instead of [ ]: a dictionary
2ModuleNotFoundError: No module named 'Pandas'import pandas, in small letters
3NameError: name 'p' is not definedpd.Series, the alias is pd
4NameError: name 's' is not definedpd.Series(stud): pass the dictionary
student_series.py
import pandas as pd
stud={'Name':'Ramya','Class':11,'House':'Red'}
s=pd.Series(stud)
print(s)
Output
Name     Ramya
Class       11
House      Red
dtype: object
In the exam
Write out the whole corrected program, and underline every word you changed. Look out for the usual suspects: a missing 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

Ways to create a Series
SourceExampleIndex you get
Emptypd.Series()none (empty)
Listpd.Series([1, 2, 3])default 0, 1, 2
List + indexpd.Series(data, index=labels)your labels
NumPy arraypd.Series(np.array([...]))default 0, 1, 2
Dictionarypd.Series({'a': 1})the dict keys
Scalarpd.Series(9, index=[...])your labels (one copy each)
Quick Check

You build a Series from a dictionary. What becomes the index?

Quick Check

What does pd.Series(9) give, with no index?