Python for Data Analysis: A Beginner's Step-by-Step Guide
Quick answer
A beginner's walkthrough of Python for data analysis using one small runnable example, from loading and cleaning to a labelled chart.
Python for data analysis means using Python with a small set of libraries, mainly pandas, NumPy and a plotting library, to load data, clean it, summarise it and chart it in a repeatable script or notebook. A beginner can do useful analysis with about twenty pandas functions and basic Python syntax. You do not need to learn software development first.
Key takeaways
- Learn in this order: Python basics, pandas, simple charts, then NumPy and statistics as you need them.
- Every analysis follows the same loop: load, inspect, clean, summarise, visualise, explain. Practise the loop, not isolated functions.
- Python does not replace Excel or SQL. It earns its place when the work must be repeated, the file is too big for a spreadsheet, or several sources must be combined.
- One small analysis of a dataset you care about teaches more than a long syntax course.
On this page:
- When should you use Python instead of Excel or SQL?
- What do you need to install?
- How do you load and inspect data?
- How do you clean data in Python?
- How do you summarise and answer questions?
- How do you chart the result?
- What should a beginner learn in the first four weeks?
- Frequently asked questions
When should you use Python instead of Excel or SQL?
Use Python when the analysis has to be rerun, audited or scaled. For a one-off look at a small sheet, Excel is quicker. For pulling rows out of a company database, SQL is the right tool. Most analysts use all three.
| Situation | Excel | SQL | Python |
|---|---|---|---|
| Quick look at a few thousand rows | Good fit | Overkill | Works, slower to start |
| Data lives in a database | Needs an export | Good fit | Good after a SQL query |
| Same report every week | Manual repetition | Good for the query part | Good fit: rerun the script |
| Combining CSV, Excel and API data | Painful | Not designed for it | Good fit |
| Messy text, dates, duplicates | Possible, error-prone | Limited | Good fit |
| Statistics or machine learning later | Limited | Limited | Good fit |
For a deeper comparison of the two code-based options, see SQL vs Python for data analysts.
What do you need to install?
You need Python, three libraries and a notebook. That is the whole toolkit for the first few months.
- pandas for tables. Its documentation describes it as a Python package that provides fast, flexible, and expressive data structures for labelled, tabular data.
- NumPy for fast numeric arrays. The NumPy beginner guide calls it an open source library widely used in science and engineering. pandas stores numeric columns as NumPy arrays underneath.
- Matplotlib for charts. pandas uses it behind its
.plot()method. - A notebook. The Jupyter documentation describes JupyterLab as a tabbed multi-notebook editing environment. A notebook lets you run code in small cells and see each result immediately, which suits exploration.
Install everything with one command in a terminal:
pip install pandas numpy matplotlib jupyterlabIf you cannot install software on your machine, a hosted notebook such as Google Colab runs the same code in a browser.
How do you load and inspect data?
Load the file into a DataFrame, then look before you calculate. A DataFrame is pandas' table: rows, named columns, one data type per column.
The example below builds a tiny, illustrative order table for a grocery delivery business so you can run it without downloading anything. With a real file you would write pd.read_csv("orders.csv") or pd.read_excel("orders.xlsx") instead.
import pandas as pd
orders = pd.DataFrame({
"order_id": [101, 102, 103, 104, 105, 106],
"city": ["Pune", "Indore", "Pune", "Kochi", "Indore", "Pune"],
"category": ["Grocery", "Snacks", "Snacks", "Grocery", "Grocery", "Snacks"],
"amount": [450, 120, None, 800, 300, 150],
"date": ["2026-01-05", "2026-01-05", "2026-01-06",
"2026-01-06", "2026-01-07", "2026-01-07"],
})
orders.info() # column names, types, non-null counts
print(orders.head()) # first five rows
print(orders.describe()) # count, mean, min, max for numeric columns
Read the info() output carefully. Here it shows two problems: amount has 5 non-null values out of 6, and date is stored as text, not as a date. Spotting these early is the habit that separates a careful analyst from a careless one.
How do you clean data in Python?
Fix types, handle missing values and remove duplicates, and write down each decision. Cleaning choices change the answer, so they must be visible in the code.
print(orders.isna().sum()) # amount: 1 missing
orders["date"] = pd.to_datetime(orders["date"])
orders["amount"] = orders["amount"].fillna(orders["amount"].median())
orders = orders.drop_duplicates(subset="order_id")
The missing amount is filled with the median of the other five orders, which is 300. That is a judgement call. Three options and when each is reasonable:
- Drop the row when few rows are affected and they are not systematically different.
- Fill with median or a group median when you need every row and the column is numeric.
- Go back to the source when the value matters, for example a large order. This is often the correct answer at work.
More patterns are in the guide to data cleaning techniques in Excel, SQL and Python.
How do you summarise and answer questions?
Turn the business question into "group by something, calculate something". Most descriptive analysis is that one move repeated.
Question: which city brings in the most revenue, and how large is a typical order there?
by_city = orders.groupby("city")["amount"].agg(["count", "sum", "mean"])
print(by_city.sort_values("sum", ascending=False))
count sum mean
city
Pune 3 900.0 300.0
Kochi 1 800.0 800.0
Indore 2 420.0 210.0
Now interpret it like an analyst. Pune leads on revenue, but with three orders. Kochi's 800 comes from a single order, so its mean says little. One of Pune's amounts was filled in by you. A good write-up states all three points instead of announcing "Pune is our top city".
A second cut, by city and category, uses a pivot table, the same idea as in Excel:
print(orders.pivot_table(index="city", columns="category",
values="amount", aggfunc="sum", fill_value=0))
How do you chart the result?
Call .plot() on the summary and label it. Choose the chart from the question: bars to compare categories, lines for change over time, histograms for the spread of one number.
import matplotlib.pyplot as plt
ax = by_city["sum"].sort_values().plot(kind="barh", title="Revenue by city (illustrative)")
ax.set_xlabel("Amount in rupees")
plt.tight_layout()
plt.savefig("revenue_by_city.png")
A chart with a title, axis label and unit is finished. One without them is a draft. For real cases to practise on, see these real-world data analysis examples.
What should a beginner learn in the first four weeks?
Follow a narrow path and finish one analysis. The plan below assumes about an hour a day and is a suggestion, so adjust the pace to your schedule.
- Week 1, Python basics: variables, lists, dictionaries, loops, functions, reading error messages.
- Week 2, pandas core: read a CSV, select columns, filter rows, sort, handle missing values. The pandas tutorial for beginners covers this step by step.
- Week 3, summarising:
groupby,merge, pivot tables, dates, plus five charts. - Week 4, one project: pick a public dataset, ask three questions, answer them in a notebook with short written conclusions.
After that, add NumPy with the NumPy tutorial for beginners, and browse the wider set of Python libraries for data analysis when a task demands one.
Next step: run the code on this page, then swap in a CSV of your own, such as your bank statement export or a public cricket dataset. If you want a structured path in data analytics, the Certification Program in Data Analytics with AI and Gen AI from E&ICT Academy, IIT Roorkee is a 06-month programme.
Frequently asked questions
Is Python hard to learn for data analysis if I have no coding background?
No. Data analysis uses a small part of Python: variables, lists, dictionaries, functions and the pandas library. Many commerce and arts graduates learn it. Expect the first two weeks to feel slow, then progress speeds up once you can read error messages.
Which Python libraries are used for data analysis?
pandas for tables, NumPy for numeric arrays and Matplotlib for charts form the base. Seaborn is common for statistical charts, and scikit-learn is added when you move to machine learning. Start with pandas alone.
Should I learn Python or SQL first for data analysis?
If your target is an analyst job, learn SQL basics first because most company data sits in databases, then Python. If you are a student exploring datasets in files, start with Python. You will need both within a few months.
Can Python replace Excel for data analysis?
It can do everything Excel does with data, but replacement is rarely the goal. Excel is quicker for small one-off tasks and for sharing with non-technical colleagues. Python is better for large files, repeated reports and combining sources.
Do I need to learn NumPy before pandas?
No. You can start with pandas directly and pick up NumPy when you need array maths, random numbers or faster numeric operations. Knowing that pandas columns are built on arrays is enough at the start.