Introduction
If you’re just starting out with data analysis, this first tutorial will walk you through the entire workflow — from creating raw data to uncovering your first real insight — using Python’s two most essential libraries: Pandas and Matplotlib.
By the end of this tutorial, you’ll be able to:
- Create data using Python
- Store data in a Pandas DataFrame
- Explore the data
- Calculate basic statistics
- Create a simple visualization
- Find a useful insight
Think of this as the “Hello World” of data analysis — small enough to grasp in one sitting, but it covers the exact same steps you’ll repeat on every real-world project, no matter how large the dataset.
Step 1: Create a New Notebook
Open JupyterLab and create a new notebook:
File → New → Notebook → Python 3
Rename it to:
01_First_Data_Analysis.ipynb
What is a Jupyter Notebook?
A Jupyter Notebook is an interactive document where you can combine code, output, explanations, and visualizations — all in one place. This makes it the go-to tool for data analysts, because you can see the result of each step immediately below the code that produced it, rather than running an entire script blindly.
Step 2: Import the Libraries
In a new code cell, run:
import pandas as pd
import matplotlib.pyplot as plt
What are these libraries, and why do we need them?
| Library | Purpose |
|---|---|
| pandas | The core library for working with tabular (row-and-column) data — think of it as Excel inside Python |
| matplotlib | Used for creating charts and visualizations |
You’ll notice we import them with short nicknames: pd for pandas and plt for matplotlib. These aren’t required, but they’re a near-universal convention in the Python data community — so much so that using them makes your code instantly recognizable to other analysts.
Step 3: Create Your First Dataset
Let’s analyze monthly sales data:
data = {
"Month": ["January", "February", "March", "April", "May", "June"],
"Sales": [10000, 15000, 12000, 18000, 22000, 20000]
}
What’s happening here?
This is a Python dictionary — a collection of key-value pairs. Each key becomes a column:
"Month"→ January, February, March…"Sales"→ 10000, 15000, 12000…
A dictionary like this is one of the most common ways to hand raw data over to Pandas before it becomes a proper table.
Step 4: Create a DataFrame
df = pd.DataFrame(data)
What is a DataFrame?
A DataFrame is Pandas’ core data structure — essentially a table or spreadsheet, with labeled rows and columns, that lets you filter, sort, calculate, and visualize data with simple commands.
Display it:
df
Output:
| Month | Sales | |
|---|---|---|
| 0 | January | 10000 |
| 1 | February | 15000 |
| 2 | March | 12000 |
| 3 | April | 18000 |
| 4 | May | 22000 |
| 5 | June | 20000 |
Notice the numbers on the left (0–5) — that’s the index, automatically assigned by Pandas to label each row.
Step 5: Explore the Data
Before analyzing anything, it’s good practice to get a feel for your dataset. Here’s a quick toolkit:
View the first few rows:
df.head()
View the last few rows:
df.tail()
(Useful for spot-checking large datasets — head() and tail() show you 5 rows by default so you don’t have to print the entire table.)
Check the number of rows and columns:
df.shape
Output:
(6, 2)
This means 6 rows and 2 columns.
Get structural information about the data:
df.info()
This tells you the column names, data types (numbers vs. text), and whether any values are missing — a critical first check before doing any real analysis.
Get basic statistics:
df.describe()
This instantly gives you:
- Count — how many values
- Mean — the average
- Min / Max — the smallest and largest values
- Standard deviation — how spread out the values are
This single command is often the fastest way to sanity-check a numeric column.
Step 6: Analyze the Data
Now let’s dig into the numbers directly:
Total sales:
df["Sales"].sum()
Average sales:
df["Sales"].mean()
Highest sales value:
df["Sales"].max()
Which month had the highest sales?
df.loc[df["Sales"].idxmax()]
Expected result:
Month May
Sales 22000
🔍 Our first data insight: May had the highest sales, with ₹22,000.
(A quick note on idxmax(): it returns the index of the row with the maximum value, and .loc[] then retrieves that entire row — a two-step pattern you’ll use constantly to find “the row where X is highest/lowest.”)
Step 7: Create a Line Chart
plt.plot(df["Month"], df["Sales"], marker="o")
plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales (₹)")
plt.show()
This creates a line chart that traces the sales trend month-over-month (January → June). Line charts are ideal when you want to visualize a trend or progression over time — the eye naturally follows the line to spot increases and decreases.
Step 8: Create a Bar Chart
plt.bar(df["Month"], df["Sales"])
plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales (₹)")
plt.show()
While a line chart is great for trends, a bar chart is better when you want to directly compare values across categories — here, comparing one month’s sales against another.
Final Analysis & Takeaway
Putting it all together: sales increased steadily from January through May, peaking at ₹22,000 in May, before dipping slightly to ₹20,000 in June.
This simple exercise mirrors the exact workflow you’ll follow on every data analysis project, big or small:
Raw Data → Create DataFrame → Explore Data → Calculate Statistics → Visualize Data → Find Insights
