Python Pandas Tutorial for Beginners (2026)
Python Pandas Tutorial for Beginners (2026)
What is Pandas?
Pandas is one of the most popular Python libraries used for working
with data. It helps you read, organize, clean, analyze, and manipulate data
easily.
If you have data stored in an Excel file, CSV file,
database, or even on a website, Pandas allows you to work with that data using
just a few lines of Python code.
Before Pandas, programmers had to write many lines of code
to perform simple data operations. Pandas simplifies these tasks and makes data
analysis much faster.
Think of Pandas Like This
Imagine you have a notebook containing information about
students.
|
Roll No |
Name |
Marks |
|
1 |
Amit |
85 |
|
2 |
Priya |
90 |
|
3 |
Rahul |
78 |
Instead of calculating averages, finding missing marks, or
sorting students manually, Pandas can do all these tasks in seconds.
Why Do We Use Pandas?
Pandas is used because it makes working with data easy.
- Read
CSV files
- Read
Excel files
- Read
JSON files
- Clean
messy data
- Remove
duplicate records
- Fill
missing values
- Filter
data
- Sort
data
- Analyze
data
- Create
reports
- Prepare
data for Machine Learning
Flowchart: How Pandas Works
Raw
Data
│
┌──────────┴──────────┐
│ │
CSV File Excel File
│ │
└──────────┬──────────┘
│
Read Using
Pandas
(pd.read_csv(), read_excel())
│
▼
Create
DataFrame
│
┌──────────┼──────────┐
│ │ │
Clean Data Analyze Filter Data
│ │ │
└──────────┼──────────┘
▼
Final
Clean Data
│
Charts /
Reports
│
Machine
Learning
Installing Pandas
pip install pandas
Import Pandas
import pandas as pd
pd is a short name for Pandas.
What is a DataFrame?
A DataFrame is the most important object in Pandas.
It is a two-dimensional table made up of rows and
columns.
It looks very similar to an Excel spreadsheet.
Example
|
Name |
Age |
City |
|
Amit |
21 |
Pune |
|
Rahul |
22 |
Mumbai |
|
Sneha |
20 |
Nashik |
This entire table is called a DataFrame.
What is a String in Python? Complete Guide with Syntax, Examples
Creating a DataFrame
import pandas as pd
student={
"Name":["Amit","Rahul","Sneha"],
"Age":[21,22,20],
"City":["Pune","Mumbai","Nashik"]
}
df=pd.DataFrame(student)
print(df)
Output
Name Age
City
0 Amit 21
Pune
1 Rahul 22
Mumbai
2 Sneha 20
Nashik
How DataFrame Works
Dictionary
│
▼
pd.DataFrame()
│
▼
Rows + Columns
│
▼
DataFrame
Real-Life Example
Think about an Excel sheet.
|
Employee ID |
Name |
Salary |
|
101 |
Amit |
25000 |
|
102 |
Priya |
30000 |
This complete table is a DataFrame.
What is a Series?
A Series is a one-dimensional data structure.
It stores only one column of data.
You can think of it as a single column from an Excel sheet.
Example
import pandas as pd
print(marks)
Output
0 85
1 90
2 78
3 95
dtype:int64
Series Flow
List
│
▼
pd.Series()
│
▼
One Column
│
▼
Series Object
Real-Life Example
Student Marks
|
Marks |
|
85 |
|
90 |
|
78 |
|
95 |
Only one column means it is a Series.
Difference Between Series and DataFrame
|
Series |
DataFrame |
|
One column |
Multiple columns |
|
1-D |
2-D |
|
Simple |
Advanced |
|
Stores one type of information |
Stores multiple types of information |
What is Read CSV?
CSV stands for Comma Separated Values.
A CSV file stores data in rows and columns using commas.
Example CSV file
Name,Age,City
Amit,21,Pune
Rahul,22,Mumbai
Sneha,20,Nashik
Why Read CSV?
Many companies save data as CSV because:
- Small
file size
- Easy
to share
- Easy
to open
- Supported
by Excel
- Supported
by databases
Reading CSV
import pandas as pd
df=pd.read_csv("student.csv")
print(df)
Flowchart
CSV File
│
▼
pd.read_csv()
│
▼
DataFrame
│
▼
Analysis
Example Output
Name Age
City
0 Amit 21
Pune
1 Rahul 22
Mumbai
2 Sneha 20
Nashik
What is Data Cleaning?
Real-world data is rarely perfect.
It often contains:
- Missing
values
- Duplicate
records
- Wrong
spellings
- Extra
spaces
- Wrong
data types
- Empty
rows
The process of fixing these problems is called Data
Cleaning.
Example of Dirty Data
|
Name |
Age |
City |
|
Amit |
21 |
Pune |
|
Rahul |
Mumbai |
|
|
Sneha |
20 |
Nashik |
|
Rahul |
Mumbai |
Problems:
- Missing
age
- Duplicate
row
After Cleaning
|
Name |
Age |
City |
|
Amit |
21 |
Pune |
|
Rahul |
22 |
Mumbai |
|
Sneha |
20 |
Nashik |
Now the data is complete and ready for analysis.
Data Cleaning Flowchart
Raw Data
│
▼
Check Missing Values
│
▼
Fill or Remove Missing Data
│
▼
Remove Duplicate Records
│
▼
Correct Data Types
│
▼
Remove Extra Spaces
│
▼
Clean Data
│
▼
Data Analysis
Common Data Cleaning Functions
Check Missing Values
df.isnull()
Count Missing Values
df.isnull().sum()
Remove Missing Values
df.dropna()
Fill Missing Values
df.fillna(0)
Remove Duplicate Rows
df.drop_duplicates()
Rename Columns
df.rename(columns={"Old":"New"})
Change Data Type
df["Age"]=df["Age"].astype(int)
Complete Pandas Workflow
Install Pandas
│
▼
Import Pandas
│
▼
Read CSV File
│
▼
Create DataFrame
│
▼
Explore Data
│
▼
Check Missing Values
│
▼
Clean Data
│
▼
Filter & Sort
│
▼
Analyze Data
│
▼
Generate Reports
│
▼
Use in Machine Learning
Advantages of Pandas
- Easy
to learn
- Beginner-friendly
- Reads
CSV, Excel, JSON, SQL files
- Fast
data processing
- Powerful
filtering and sorting
- Handles
large datasets
- Excellent
for data analysis
- Widely
used in Data Science and Machine Learning
Frequently Asked Questions (FAQs)
1. What is Pandas in Python?
Pandas is a powerful Python library used to read, organize, clean, analyze, and manipulate structured data.
2. What is a DataFrame?
A DataFrame is a two-dimensional table with rows and columns, similar to an Excel spreadsheet.
3. What is a Series?
A Series is a one-dimensional data structure that stores a single column of data.
4. What is a CSV file?
A CSV (Comma Separated Values) file stores tabular data where each value is separated by a comma.
5. What is pd.read_csv()?
pd.read_csv() is a Pandas function that reads a CSV file and converts it into a DataFrame.
6. What is Data Cleaning?
Data Cleaning is the process of fixing or removing incorrect, missing, duplicate, or inconsistent data so it can be analyzed accurately.
7. Why is Data Cleaning important?
Clean data improves the accuracy of analysis, reports, and
machine learning models.
Interview Questions
- What
is Pandas, and why is it used in Python?
- Explain
the difference between a Series and a DataFrame.
- What
is the purpose of pd.read_csv()?
- What
types of files can Pandas read?
- How
do you create a DataFrame in Pandas?
- How
do you create a Series in Pandas?
- What
is Data Cleaning? Why is it important?
- Which
Pandas functions are used to handle missing values?
- How
do you remove duplicate rows in a DataFrame?
- Why is Pandas widely used in Data Science and Machine Learning?
Comments
Post a Comment