Python Data Analytics: pandas, Data Cleaning, Visualisation and Analysis
Python is one of the most widely used languages for working with data. This guide teaches the analytics workflow in pandas, from loading a file to cleaning, summarising, charting and testing, with code you can follow line by line.
Why Python for data?
Python is readable, free and supported by a huge ecosystem: pandas for tables, NumPy for numbers, matplotlib and seaborn for charts, SciPy and statsmodels for statistics, scikit-learn for machine learning. The same language takes you from a coursework analysis to automation and production systems.
Core building blocks
| Concept | Example |
|---|---|
| Variables and types | n = 120, rate = 0.35, name = "Lee" |
| Lists and dictionaries | [3, 5, 8], {"mode": "online"} |
| Import a library | import pandas as pd |
| Read data | df = pd.read_csv("data.csv") |
| Inspect | df.head(), df.info(), df.describe() |
| Select | df["engage"], df[["id", "mode"]] |
| Filter | df[df["age"] >= 25] |
| New column | df["engage_pct"] = df["engage"] / 5 * 100 |
| Group and summarise | df.groupby("mode")["engage"].agg(["mean", "std", "count"]) |
The analytics workflow
- Load data (
read_csv,read_excel). - Inspect shape, types and missing values (
df.info(),df.isna().sum()). - Clean: fix types (
pd.to_numeric,pd.to_datetime), standardise categories (.str.strip().str.lower()), handle missing values (dropna,fillnawith justification), remove duplicates (drop_duplicates). - Transform: new variables, merges (
pd.merge), reshaping (melt,pivot_table). - Explore: summaries and charts.
- Analyse: tests and models.
- Communicate: clear charts and a notebook others can re-run.
Worked example
Illustrative fictional data on online course activity.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from scipy import stats
df = pd.read_csv("activity.csv")
df["mode"] = df["mode"].str.strip().str.lower()
df = df.drop_duplicates(subset="student_id")
print(df.isna().sum())
summary = df.groupby("mode")["logins_per_week"].agg(["count", "mean", "median"])
print(summary)
sns.boxplot(data=df, x="mode", y="logins_per_week")
plt.ylabel("Logins per week")
plt.show()
ft = df.loc[df["mode"] == "full-time", "logins_per_week"].dropna()
pt = df.loc[df["mode"] == "part-time", "logins_per_week"].dropna()
print(stats.mannwhitneyu(ft, pt))
The cleaning steps matter: "Part-time " and "part-time" would otherwise be counted as different groups. A Mann–Whitney U test is used because login counts are typically skewed. Interpret the result alongside the medians and the chart, not the p-value alone.
Common mistakes
- Chained assignment warnings from modifying a slice; use
.loc. - Silently dropping missing data without reporting how much.
- Text categories with stray spaces or capitals.
- Running cells out of order in notebooks; restart and run all before submitting.
- Charts without labels or units.
Explore learning resources
Worked examples, worksheets and checklists to use alongside this guide. They are learning tools, not answers to an assessment: adapt them to your own task and your institution’s requirements.
ExerciseNotebook exercise: clean a messy columnPractise the most common cleaning task.
A column country contains: "India", "india ", "INDIA", "U.K.", "UK", "United Kingdom", "".
- Strip spaces and convert to lower case.
- Map UK variants to one value using a dictionary and
.replace(). - Convert empty strings to missing (
pd.NA). - Count values with
.value_counts(dropna=False).
Self-check: you should end with three categories plus missing.
ChecklistData cleaning checklistRun through this before any analysis.
- Correct data types for every column
- Missing values counted and handled with a stated rule
- Duplicates checked on the right key
- Categories standardised (case, spaces, spelling)
- Outliers inspected, not automatically deleted
- Units consistent (dates, currencies, percentages)
- Every step recorded in the notebook
Watch the topic explained
Video lesson · about 10 minutes · in production
Python Data Analytics with pandas
An original lesson that teaches Python data analytics with diagrams and a worked example, with captions and a transcript. These are the chapters it will cover; each links to the matching part of this guide.
- 01Notebooks and setup
- 02DataFrames and selecting data
- 03Cleaning real-world data
- 04Grouping and summarising
- 05Charts and a simple test
Check your understanding
3 short questions. Choose an answer for each, then check. Every answer comes with an explanation.
Take your learning further
Learn Python data analytics with a specialist Academic Expert
Sometimes a concept needs more than a written explanation. A live 1:1 session with an Academic Expert who works in Python data analytics lets you ask your own questions, work through examples at your pace and get feedback on your own thinking.
What you can work on together
- Set up Python, Jupyter and packages
- Load, inspect and clean real datasets
- Group, merge and reshape data with pandas
- Build clear charts
- Run appropriate statistical tests
- Debug your own notebook
How sessions help
- Make sense of your brief and marking criteria, so you know exactly what is being asked.
- Ask the questions you would not ask in a big class, as often as you need.
- Get timely, specific feedback on work you have written yourself.
- Practise explaining your reasoning out loud, ready for vivas, presentations and practicals.
- Extra support with academic English and conventions if English is not your first language.
Teach → coach → review. Experts explain, demonstrate and give feedback. You stay the author of your work and make the decisions in it.
Frequently asked questions
Python or R for data analysis?
Both are excellent. Python is strong for general programming and machine learning; R is strong for statistics and research graphics. Choose what your course or workplace uses.
Do I need to install anything?
You can start in the browser with tools such as Google Colab, or install Anaconda or Python with VS Code locally.
Our academic integrity commitment
UniLearno supports learning, understanding and independent academic development. Our Academic Experts explain concepts, demonstrate methods, guide research and give feedback on work you have created. We do not complete assessed work, fabricate data or references, or produce anything for you to submit. You remain responsible for your own ideas, analysis, conclusions and final submission, and for following your institution’s academic integrity and AI-use rules.
Why a shortcut costs more than it saves
- It is more visible than it looks. Markers notice when work does not match what they know of you; document history, reference lists and follow-up conversations about your work are all used to check authorship.
- It creates a lasting risk. Services that sell completed assignments have threatened students afterwards, demanding money not to tell their university.
- The gap does not go away. Later units, supervised exams, vivas, placements and the job itself all assume you have the skill.
- Help that teaches is the safer route. Understanding the brief, getting feedback early and practising with an expert closes the gap for good.
Sources and about this guide
- McKinney, W. (2022). Python for data analysis (3rd ed.). O’Reilly. (Free online.)
- pandas development team. pandas documentation. pandas.pydata.org.
- VanderPlas, J. (2016). Python data science handbook. O’Reilly. (Free online.)
- Written by
- UniLearno Learning Team
- Last reviewed
- Found an error?
- Tell us and we will check and correct it.