Series

A Series is the simplest data structure in Pandas - a single column of data paired with a matching index that labels every value. Almost everything else in Pandas, including the DataFrame, is built on top of it.

Creating a Series

A Series can be created from a list, a NumPy array, or a dictionary. If no index is supplied, Pandas automatically assigns a default numeric index starting at 0.

import pandas as pd

marks = pd.Series([88, 76, 91, 64])
print(marks)
# 0    88
# 1    76
# 2    91
# 3    64
# dtype: int64

Using a Custom Index

subjects = pd.Series([88, 76, 91], index=["Maths", "Science", "English"])
print(subjects["Science"])   # 76
print(subjects.index)        # Index(['Maths', 'Science', 'English'], dtype='object')

Creating a Series from a Dictionary

city_population = pd.Series({"Delhi": 32900000, "Mumbai": 20700000, "Noida": 700000})
print(city_population["Noida"])   # 700000

Vectorised Operations

Just like NumPy arrays, Series support fast element-wise operations without writing an explicit loop.

bonus = subjects + 5
print(bonus)
# Maths      93
# Science    81
# English    96
# dtype: int64
A Series behaves like a cross between a Python list and a dictionary - you get positional access like a list, and label based access like a dictionary, at the same time.

Coming Up Next

Next, you'll look at the DataFrame in more detail - how multiple Series come together to form a full two-dimensional table.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course