What Is Pandas?
Pandas is a Python library used to work with structured and tabular data. It makes it much easier to load, inspect, clean, filter, analyze, and prepare data for Machine Learning and AI.
Pandas helps you work with real-world data.
NumPy is excellent for numerical arrays, but real-world datasets usually contain rows, columns, names, categories, missing values, and other information. Pandas gives us convenient structures and tools for working with that kind of data.
What Is Pandas?
Pandas is an open-source Python library designed for data manipulation and analysis.
The name comes from the term Panel Data, a term used in statistics and economics for structured datasets.
In simple terms:
Think of Pandas as a powerful spreadsheet tool for Python.
Imagine an Excel spreadsheet containing thousands or millions of rows. Pandas lets you perform similar operations directly from Python code, while also making the data easy to use in Data Science and Machine Learning workflows.
Why Do We Need Pandas?
Suppose we have customer information:
Name Age City Raj 29 Hyderabad John 32 London Sarah 27 New York David 35 Chicago
We might want to answer questions such as:
- Which customers are older than 30?
- How many customers are from London?
- What is the average age?
- Which city has the most customers?
- Are any values missing?
Pandas provides simple tools for performing these operations.
Pandas vs NumPy
You just completed NumPy, so this distinction is important.
NumPy
Mainly focuses on numerical arrays and mathematical operations.
Pandas
Focuses on structured data such as tables, columns, rows, labels, and datasets.
A simple way to remember it:
NumPy = numerical calculations
Pandas = working with structured datasets
Installing Pandas
If Pandas is not already installed, you can install it using pip.
pip install pandas
If you are using a virtual environment, make sure the environment is activated before installing Pandas.
Import Pandas
The standard way to import Pandas is with the
pd alias.
import pandas as pd
The pd alias is simply a shorter name for
Pandas. It allows us to write:
pd.DataFrame() pd.read_csv() pd.Series()
Your First Pandas Example
Let's create a small table using Pandas.
import pandas as pd
data = {
"Name": ["Raj", "John", "Sarah"],
"Age": [29, 32, 27],
"City": ["Hyderabad", "London", "New York"]
}
df = pd.DataFrame(data)
print(df)
Name Age City 0 Raj 29 Hyderabad 1 John 32 London 2 Sarah 27 New York
We created a Pandas DataFrame.
A DataFrame is essentially a table with rows and columns. We will study DataFrames in detail in the next lessons.
Understanding the DataFrame
Look at the table again:
Name Age City 0 Raj 29 Hyderabad 1 John 32 London 2 Sarah 27 New York
Here:
- Name is a column.
- Age is a column.
- City is a column.
- Each horizontal line represents a row.
- The numbers on the left are row indexes.
This table-like structure is one of the main reasons Pandas is so useful for Data Science.
Access a Column
We can select one column from the DataFrame.
print(df["Name"])
0 Raj 1 John 2 Sarah Name: Name, dtype: object
Pandas returns the column as a Series.
We will learn exactly what a Series is in the next lesson.
Why Pandas Is Important for AI
Machine Learning models cannot simply consume a messy CSV file and magically understand it.
Before training a model, we often need to:
- Load the dataset.
- Inspect the data.
- Find missing values.
- Filter unwanted records.
- Sort and organize the data.
- Calculate statistics.
- Prepare columns for Machine Learning.
Pandas is one of the main Python tools used for these tasks.
Real-World Example
Imagine you have an e-commerce dataset containing 100,000 orders:
Order ID | Product | Price | Quantity | Country 1001 | Laptop | 900 | 1 | USA 1002 | Mouse | 25 | 2 | UK 1003 | Laptop | 900 | 1 | India ...
With Pandas, you could load this data and ask:
import pandas as pd
orders = pd.read_csv("orders.csv")
print(orders.head())
Later, you could filter orders, calculate revenue, find missing values, group orders by country, and prepare the dataset for a Machine Learning model.
Those operations are exactly what we will learn in the upcoming Pandas lessons.
How Pandas Builds on NumPy
Pandas is not completely separate from the numerical Python ecosystem. Pandas uses NumPy heavily underneath.
This is why your previous NumPy knowledge is useful.
NumPy
Excellent when you mainly need fast numerical array operations.
Pandas
Better when your data has meaningful rows, columns, labels, different data types, and real-world structure.
What You Will Learn in This Pandas Lesson
This lesson introduces Pandas. The following lessons will build the skills step by step:
- Series — one-dimensional labeled data.
- DataFrames — table-like data with rows and columns.
- Reading CSV — load real datasets.
- Filtering Data — select the records you need.
- Sorting Data — organize your dataset.
- Missing Data — handle incomplete values.
- GroupBy — summarize data by categories.
- Pandas Project — combine everything into one project.
Pandas makes structured data easier to work with.
NumPy gives you powerful numerical arrays. Pandas takes that foundation and gives you a convenient way to work with real-world datasets containing rows, columns, labels, and different types of information. In AI and Machine Learning, Pandas is commonly used before the data reaches the model because the data usually needs to be inspected, cleaned, filtered, and prepared first.