Pandas Basics
Pandas is the standard Python library for working with tables of data. If your data lives in a spreadsheet or a CSV file — rows of records, columns of fields — Pandas is the tool you reach for to load, clean, filter, and summarise it. Since most machine learning starts with messy tabular data, Pandas is where a lot of real AI work actually happens.
The DataFrame
The central object in Pandas is the DataFrame: a table with labelled rows and columns, much like a spreadsheet. Each column can hold a different type (numbers, text, dates), and you can select, filter, and transform the data with short, readable commands.
import pandas as pd
# Build a small DataFrame from a dictionary.
data = {
"name": ["Asha", "Ravi", "Meera"],
"age": [21, 23, 22],
"score": [88, 76, 95],
}
df = pd.DataFrame(data)
print(df)
# name age score
# 0 Asha 21 88
# 1 Ravi 23 76
# 2 Meera 22 95
Loading real data
Most of the time you load data from a file rather than typing it. CSV is the most common format.
import pandas as pd
# Read a CSV file into a DataFrame.
df = pd.read_csv("students.csv")
# Quick first looks at any new dataset:
print(df.head()) # first 5 rows
print(df.shape) # (rows, columns)
print(df.info()) # column names, types, and missing-value counts
print(df.describe()) # summary statistics for numeric columns
Running head, info, and describe on any new dataset is a good habit — it tells you the size, the types, and where data might be missing before you do anything else.
Selecting columns and rows
You can pick out the parts of the data you care about.
import pandas as pd
df = pd.DataFrame({
"name": ["Asha", "Ravi", "Meera"],
"age": [21, 23, 22],
"score": [88, 76, 95],
})
print(df["score"]) # one column (a Series)
print(df[["name", "score"]]) # several columns (a DataFrame)
# Filter rows with a condition: students scoring above 80.
high = df[df["score"] > 80]
print(high)
That filtering style — passing a condition inside the brackets — is one of the most-used Pandas patterns.
Want to learn this properly?
Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.
Browse coursesHandling missing data
Real datasets have gaps. Pandas marks missing values as NaN, and gives you ways to find and fix them.
import pandas as pd
import numpy as np
df = pd.DataFrame({
"age": [21, np.nan, 22],
"score": [88, 76, np.nan],
})
print(df.isna().sum()) # count missing values per column
# Option 1: drop rows with any missing value.
clean = df.dropna()
# Option 2: fill missing values, e.g. with the column average.
filled = df.fillna(df.mean(numeric_only=True))
print(filled)
Deciding whether to drop or fill missing values is a real choice that affects your model. It is a core part of data preprocessing.
Creating and summarising columns
You can add new columns and group data to summarise it.
import pandas as pd
df = pd.DataFrame({
"subject": ["maths", "maths", "science"],
"score": [90, 70, 85],
})
# New column based on a condition.
df["passed"] = df["score"] >= 75
# Group by subject and get the average score per group.
print(df.groupby("subject")["score"].mean())
groupby is the Pandas way of answering "average per category" questions, which come up constantly in analysis.
Common mistakes
- Editing a slice and expecting it to change the original. Pandas may warn about setting values on a copy. Use
.locfor clear, reliable assignment, e.g.df.loc[df["age"] > 21, "score"] = 100. - Ignoring data types. A column of numbers stored as text will not do maths correctly. Check
df.dtypesand convert when needed. - Dropping missing data without thinking.
dropna()is quick but can throw away a lot of rows. Consider whether filling values is better. - Forgetting Pandas is built on NumPy. Understanding NumPy basics makes many Pandas behaviours clearer.
FAQ
Is Pandas only for machine learning? No. It is used widely for data analysis, reporting, and cleaning. ML is one common use among many.
Do I need NumPy before Pandas? A little NumPy helps, since Pandas builds on it, but you can learn them side by side.
How big a dataset can Pandas handle? Comfortably up to data that fits in your computer's memory. Very large datasets need other tools, but most learning projects fit fine.
Keep learning
Explore the full AI & machine learning hub for more guides, or join the waitlist for our structured Artificial Intelligence course at Infoplanet, Jalgaon, to learn Pandas and ML hands-on with mentor support.
Want to learn this properly?
Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.
Browse coursesFounder, Atlee Technologies
Yash Kabra is the founder of Atlee Technologies, a product studio that ships SaaS products end-to-end. He owns products from strategy through launch and growth — including Infoplanet, TrackRise and Perqee — and teaches AI, Machine Learning and Data Science at Infoplanet with a focus on how these tools are used to build real products.
Related guides
AI Career Roadmap
A practical path into AI: build programming and maths foundations, learn the core machine learning workflow, then deepen into a specialism and prove it with projects.
AI vs ML vs Deep Learning
AI is the broad goal of intelligent machines; machine learning is one way to reach it by learning from data; deep learning is a powerful subset of machine learning using neural networks.
Classification vs Regression
Classification predicts a category; regression predicts a number. Both are supervised learning — the type of answer you want decides which one you use.
