Beginner's Guide to Pandas Series with Real-World Examples


Pandas is a powerful open-source library built on top of the Python programming language. It's widely used for data analysis and manipulation tasks and integrates seamlessly with NumPy.
In this blog, we’ll focus on Pandas Series. A core component of Pandas.
What is a Pandas Series?
A Pandas Series is a one-dimensional labeled array capable of holding any data type (integers, strings, floats, Python objects, etc.). Think of it like a single column in a table.
import pandas as pd
import numpy as np
Creating Series
1. From a List (Default Index)
country = ['Pakistan', 'India', 'USA', 'Korea', 'Japan']
pd.Series(country)
2. From a List (Custom Index)
marks = [99, 97, 98, 95, 97]
courses = ['Financial Accounting', 'Linear Algebra', 'Data Structures & Algorithms', 'App of ICT', 'OOP LAB']
pd.Series(marks, index=courses)
3. From a Dictionary
marks_dict = {'Eng': 87, 'Maths': 97, 'Science': 76}
pd.Series(marks_dict, name='Shehraz Marks')
Series Attributes
marks_series.size # Number of elements
marks_series.dtype # Data type
marks_series.name # Series name
marks_series.index # Index labels
marks_series.values # Series values
marks_series.is_unique # True if all values are unique
Series from CSV
subs = pd.read_csv('subs.csv').squeeze("columns")
virat_runs = pd.read_csv('kohli_ipl.csv', index_col='match_no').squeeze("columns")
movies = pd.read_csv('bollywood.csv', index_col='movie').squeeze("columns")
Series Methods
Head, Tail, Sample
subs.head() # First 5 rows
virat_runs.tail(10) # Last 10 rows
movies.sample(5) # 5 random values
Value Counts
movies.value_counts(ascending=True)
Sorting
virat_runs.sort_values(ascending=False).head(1) # Highest score
movies.sort_index(ascending=False) # Sort by index
Mathematical Methods
subs.sum(), subs.mean(), subs.median(), subs.std(), subs.var()
virat_runs.describe() # Statistical summary
Indexing & Slicing
x = pd.Series([1, 23, 231, 54, 4, 10])
x[3] # Positive index
movies.iloc[0] # Integer location
movies['Uri: The Surgical Strike'] # Label index
virat_runs[5:16] # Slicing
movies[-5:] # Negative slicing
Editing a Series
x[3] = 55
marks_series.iloc[2] = 84
marks_series['FAP'] = 99 # Append new entry
Series with Python Functionalities
len(subs), type(subs), sorted(marks_series)
list(marks_series), dict(marks_series)
'Salman Khan' in movies.values
Arithmetic & Relational Operators
100 - marks_series # Broadcasting
virat_runs >= 50 # Boolean indexing
Boolean Indexing (Use Cases)
virat_runs[virat_runs >= 50].size # 50s and 100s
virat_runs[virat_runs == 0].size # Ducks
subs[subs > 200].size # High-subscriber days
movies.value_counts()[movies.value_counts() > 20] # Actors with >20 movies
Plotting Series
subs.plot()
movies.value_counts().head(20).plot(kind='pie')
Conclusion
A Pandas Series is more than just a column of data. it’s a powerful container with methods and attributes that make analysis seamless. Whether you're dealing with sports stats, YouTube growth, or Bollywood data, mastering Series is your first step into Pandas.
Bonus Resources
- 📘 Explore My Practical Notebooks: My GitHub Repository on Python & Pandas . This repo includes detailed Jupyter notebooks covering each method and attribute of Pandas with real-world datasets and hands-on explanations.
Keep learning, and happy coding with Pandas!
Subscribe to my newsletter
Read articles from Shehzified directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Shehzified
Shehzified
I'm Shehraz Sarwar, a CS student at IUGC and Silver Medalist from FAST. I love blending code with creativity, exploring Python, Data Science, AI, and the real-world magic of math. With a strong base in Python and Data Analysis, along with C, C++, and Java, I tackle problems through hands-on projects. Beyond code, I dive into video editing, 3D art, and UI/UX design, fueling my journey to become a versatile Computer Scientist.