Pandas – Data Manipulation
Pandas is a powerful Python library used for data analysis and
data manipulation.
It helps you:
Read data (Excel, CSV, etc.)
Clean data
Analyze data
Work with tables easily
Think of Pandas like Excel inside Python.
🔹 Why use Pandas?
Easy to handle large datasets
Fast and efficient
Works well with NumPy
Used in Data Science & Data Analysis
🔹 Main Data Structures
1. Series (1D data)
Like a single column in Excel
import pandas as pd
data = [Link]([10, 20, 30, 40])
print(data)
2. DataFrame (2D data)
Like a table (rows & columns)
import pandas as pd
dataf = {
"Name": ["Renu", "Amit", "Sita"],
"Age": [25, 30, 22],
“Class”: [12,11,12]
}
df = [Link](dataf)
print(df)
🔹 Reading Data
From CSV file
df = pd.read_csv("[Link]")
From Excel file
Python -m pip install openpyxl
df = pd.read_excel("[Link]")
🔹 Basic Functions
View data
[Link]() # First 5 rows
[Link]() # Last 5 rows
Check structure
[Link]() # Data types
[Link]() # Statistics
🔹 Selecting Data
df["Name"] # Single column
df[["Name","Age"]] # Multiple columns
Filter data
df[df["Age"] > 25]
🔹 Adding New Column
df["Salary"] = [20000, 30000, 25000]
🔹 Handling Missing Data
[Link]() # Check missing values
[Link]() # Remove missing values
[Link](0) # Replace missing values
🔹 Simple Analysis
df["Age"].mean() # Average
df["Age"].max() # Maximum
df["Age"].min() # Minimum
🔹 Grouping Data
[Link]("Age").count()
🔹 Sorting Data
df.sort_values("Age")
🔹 Save Data
df.to_csv("[Link]")
example:
merge= [Link](df1,df2, on="Sr. No.")
print(merge)
merge.to_excel("D:\Python_Projects\
merged_file.xlsx",index=False)
(Easy Words)
Pandas = Tool to work with data
Series = 1 column
DataFrame = Table
Used for cleaning, analyzing, and organizing data
Matplotlib – Data Visualization
Matplotlib is a Python library used for data visualization.
It helps you create:
Graphs
Charts
Plots
Think of it like making charts in Excel, but using Python.
🔹 Why use Matplotlib?
Visualize data easily
Understand trends & patterns
Useful in Data Science & Analysis
Works well with Pandas & NumPy
🔹 Basic Import
import [Link] as plt
pyplot is the main module used for plotting.
🔹 1. Line Plot
import [Link] as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
[Link](x, y)
[Link]()
Used for: Trends over time
🔹 2. Bar Chart
x = ["A", "B", "C"]
y = [5, 7, 3]
[Link](x, y)
[Link]()
Used for: Comparing categories
🔹 3. Pie Chart
data = [30, 40, 30]
label = ["A", "B", "C"]
[Link](data, labels=label)
[Link]()
Used for: Percentage distribution
🔹 4. Scatter Plot
x = [1,2,3,4]
y = [10,15,13,17]
[Link](x, y)
[Link]()
Used for: Relationship between variables
🔹 Adding Labels & Title
[Link](x, y)
[Link]("Sample Graph")
[Link]("X Axis")
[Link]("Y Axis")
[Link]()
🔹 Multiple Lines in One Graph
x = [1,2,3,4]
y1 = [10,20,30,40]
y2 = [5,15,25,35]
[Link](x, y1)
[Link](x, y2)
[Link]()
🔹 Grid & Legend
[Link](x, y1, label="Line 1")
[Link](x, y2, label="Line 2")
[Link]()
[Link]()
[Link]()
🔹 Save Graph
[Link]("[Link]")
🔹 Summary (Simple Words)
Matplotlib = Library to create graphs
[Link]() = Line graph
[Link]() = Bar chart
[Link]() = Pie chart
[Link]() = Scatter plot
🔹 Small Tip
Use Matplotlib with:
Pandas → for data handling
NumPy → for numerical data