Courses

Pandas Tutorial for Beginners: Load, Clean and Summarise Data

Learn pandas the practical way: one small, messy sales file taken from raw CSV to a clean summary, with every line of code explained.

By Nazmul Hussain Published Updated 7 min read

A Jupyter notebook showing a small pandas DataFrame of sales orders and a grouped revenue-by-city result

Most beginners meet pandas through a long list of functions and forget them within a week. This pandas tutorial for beginners does it differently: one small, slightly messy sales file, taken from a raw CSV to a clean summary, with every line explained. By the end you’ll have used the dozen or so pandas tools that cover most everyday analysis.

Pandas is taught in month 3 of Omebly Academy’s Python course, right after the core language, because it’s where Python starts paying off for real work.

Quick answer: Import pandas, load your file with pd.read_csv(), and look at it with head(), info() and describe(). Clean it by fixing data types, trimming text, removing duplicates and handling blanks. Then summarise with groupby() and pivot_table(), and save the result with to_csv(). Learn these on one real file before anything else.

What pandas is, and what you need first

Pandas is a Python library for working with tables. Its main object is the DataFrame: rows and named columns, like a spreadsheet you control with code. A single column is a Series.

Before you start you need:

  • Basic Python: variables, lists, dictionaries, functions and imports. If you’re not there yet, start with our Python learning roadmap.
  • Python 3 installed, plus pandas: python -m pip install pandas.
  • A place to run code: a Jupyter notebook is easiest for learning, because you see each table as you go.

A note on pandas 3.0

Pandas 3.0 was released in January 2026. Two changes matter to beginners: text columns now get a dedicated string type by default, and Copy-on-Write is the only mode. The practical effect is in step 5 below. The pandas 3.0 release notes cover the details, and the code in this tutorial works on current pandas.

The sample file

Save this as sales.csv. It’s tiny on purpose, with problems you’ll see in real files: a city with stray spaces and lower case, a missing quantity and a duplicated order.

order_id,order_date,city,product,qty,price
1001,2026-10-01,Kolkata,Kurta,2,850
1002,2026-10-01, kolkata ,Saree,1,2400
1003,2026-10-02,Pune,Kurta,,850
1004,2026-10-02,Chennai,Dupatta,3,300
1004,2026-10-02,Chennai,Dupatta,3,300
1005,2026-10-03,Kolkata,Saree,1,2400

Step 1: Load the data

import pandas as pd

df = pd.read_csv("sales.csv")

pd is the standard nickname everyone uses. read_csv reads the file into a DataFrame called df. For Excel files use pd.read_excel("file.xlsx"), which needs the openpyxl package installed.

Step 2: Look before you touch anything

df.head()        # first 5 rows
df.shape         # (6, 6): rows, columns
df.info()        # column names, types, non-null counts
df.describe()    # count, mean, min, max for number columns

info() is the most useful line here. It shows that qty has only 5 non-null values out of 6, which tells you something is missing. It also shows order_date stored as text, not as a date.

Two more quick checks

df["city"].value_counts()   # spot spelling and spacing variants
df.duplicated().sum()       # 1 fully duplicated row

value_counts() lists “Kolkata” and “ kolkata “ as different cities, which is exactly the kind of problem that quietly breaks totals.

Step 3: Clean the data

Cleaning is most of the job. Our data cleaning checklist covers the full process; here are the steps this file needs.

Fix data types

df["order_date"] = pd.to_datetime(df["order_date"])

Now dates sort correctly and you can pull out the month or weekday later with df["order_date"].dt.month.

Tidy text columns

df["city"] = df["city"].str.strip().str.title()

str.strip() removes spaces at both ends and str.title() makes “kolkata” into “Kolkata”. Run value_counts() again and you’ll see just three cities.

Remove duplicates

df = df.drop_duplicates()

Order 1004 now appears once. In real data, check duplicates on the key column too, with df.duplicated(subset="order_id"), because two rows can share an order ID while differing in a small detail.

Handle missing values

Order 1003 has no quantity. You have three honest options: find the real value, drop the row, or fill it with a sensible default and note that you did.

df["qty"].isna().sum()            # how many are missing: 1
df["qty"] = df["qty"].fillna(1)   # business rule: assume 1 unit
df["qty"] = df["qty"].astype("int64")

The column was stored as decimals because of the blank, so astype("int64") turns it back into whole numbers. Never fill blanks without writing down why; a filled value is a guess.

Step 4: Add calculated columns

df["revenue"] = df["qty"] * df["price"]

Pandas works on whole columns at once, so there’s no loop. The revenue column now reads 1,700, 2,400, 850, 900 and 2,400.

Step 5: Filter rows the right way

kolkata = df[df["city"] == "Kolkata"]
big_orders = df.loc[df["revenue"] >= 2000, ["order_id", "city", "revenue"]]

The pattern df.loc[rows, columns] is worth memorising: a condition for rows, a list for columns.

Changing values: use .loc, not chained assignment

With Copy-on-Write in pandas 3.0, this older style no longer changes df:

# Doesn't update df in pandas 3.0
df["price"][df["product"] == "Kurta"] = 900

Write it in one step with .loc instead:

df.loc[df["product"] == "Kurta", "price"] = 900

Old tutorials online still show the first form, so this is the change most likely to confuse you.

Step 6: Summarise with groupby

groupby answers “per something” questions: revenue per city, orders per product, average order per month.

by_city = (
    df.groupby("city")["revenue"]
      .sum()
      .sort_values(ascending=False)
)
city revenue
Kolkata 6500
Chennai 900
Pune 850

(Those totals use the original prices, before the Kurta price change in step 5.)

Several summaries at once

summary = df.groupby("product").agg(
    orders=("order_id", "count"),
    units=("qty", "sum"),
    revenue=("revenue", "sum"),
)

Named aggregation, as above, gives you clear column names instead of a confusing multi-level header.

Pivot tables

If you know Excel pivot tables, pivot_table will feel familiar:

pivot = df.pivot_table(
    index="city", columns="product",
    values="revenue", aggfunc="sum", fill_value=0,
)

Cities become rows, products become columns, and blanks become 0.

Step 7: Combine tables with merge

Real data usually lives in more than one file. If you have a cities.csv with each city’s region, join it like this:

cities = pd.read_csv("cities.csv")   # columns: city, region
df = df.merge(cities, on="city", how="left")

how="left" keeps every sales row even if a city is missing from the lookup, just like a SQL LEFT JOIN. Check df.shape before and after: if the row count grows, the lookup file has duplicate cities.

Step 8: Save your work

by_city.to_csv("revenue_by_city.csv")
df.to_excel("clean_sales.xlsx", index=False)

index=False stops pandas writing its row numbers as an extra column.

Pandas cheat sheet for beginners

Task Code
Load a CSV pd.read_csv("file.csv")
First rows df.head()
Types and blanks df.info()
Count values df["col"].value_counts()
Convert to date pd.to_datetime(df["col"])
Trim text df["col"].str.strip()
Remove duplicates df.drop_duplicates()
Fill blanks df["col"].fillna(value)
Filter and select df.loc[condition, ["a", "b"]]
Group and total df.groupby("a")["b"].sum()
Pivot df.pivot_table(index=, columns=, values=)
Join df.merge(other, on="key", how="left")
Save df.to_csv("out.csv", index=False)

Common beginner mistakes

  • Cleaning before looking. Run info() and value_counts() first, or you’ll fix the wrong things.
  • Forgetting to save the result. df.drop_duplicates() returns a new DataFrame; write df = df.drop_duplicates().
  • Loops over rows. If you’re writing for row in df.iterrows(), there’s almost always a column-wise way.
  • Chained assignment. Use .loc for changes, as in step 5.
  • Silent fills. Filling blanks with 0 can drag averages down; decide per column.
  • Not counting rows after a merge. Duplicate keys multiply rows without warning.

Practice tasks

Use the sample file, or any public dataset, and try these:

  1. Total revenue by day, sorted by date.
  2. The best-selling product by units in each city.
  3. Average order value per city.
  4. A pivot of units by city and product.
  5. Every order above the average order value.

When these feel easy, turn one into a small notebook project with a short write-up. Our list of Python project ideas for beginners includes a sales report project that builds on exactly this.

Learn it with Omebly

Omebly Academy’s Python course teaches pandas after the core language: month 1 covers basics, functions, collections and file handling; month 2 covers object-oriented programming, modules, virtual environments, error handling and APIs; month 3 covers data analysis with Pandas and NumPy, data cleaning, charts and automation scripts. You work in VS Code, Jupyter and Git/GitHub, with live mentor-led classes, recordings and weekly one-to-one reviews.

  • Core (3 months, $699): months 1 to 3, with 2 capstone projects.
  • Professional (6 months, $1,199): adds web scraping, SQL with Python, testing, Flask/FastAPI basics and Git workflows, plus mock interviews and portfolio review.
  • Career (12 months, $1,999): adds an introduction to machine learning with scikit-learn, deployment and a live client-style project with the Omebly team, with placement assistance (CV help, mock interviews, portfolio review and referrals where possible, not a job guarantee).

Want to check which track fits you? Message us on WhatsApp or contact us to book a free first call.

Frequently asked questions

Is pandas hard to learn for a beginner?

Not if you know basic Python first. Most day-to-day work uses a small set of tools: read_csv, head, info, loc, groupby, merge and to_csv. Learn those on a real file and the rest comes as you need it.

Do I need to know Python before learning pandas?

Yes, the basics. You should be comfortable with variables, lists, dictionaries, functions and importing libraries. A few weeks of plain Python is enough to start pandas.

What is the difference between pandas and Excel?

Excel is great for looking at and editing data by hand. Pandas is better when files are large, when the same cleaning must be repeated every week, or when you want every step written down as code that someone else can rerun and check.

What changed in pandas 3.0?

Pandas 3.0, released in January 2026, made Copy-on-Write the only mode and introduced a dedicated string dtype by default. In practice, chained assignment such as df['a'][mask] = value no longer changes the original DataFrame, so use df.loc[mask, 'a'] = value instead.

Should I use Jupyter or VS Code for pandas?

Both work. Jupyter notebooks are ideal for exploring data step by step and seeing tables as you go. VS Code is better for scripts you will run again. Many people explore in a notebook, then move the final steps into a script.

What should I learn after pandas basics?

Learn charts with Matplotlib, joining tables with merge, working with dates, and SQL so you can pull data from databases. Then build one or two small analysis projects for your portfolio.

Written by

Nazmul Hussain, Managing Director & Technical Head, Omebly. 10+ years building websites and apps for clients in India, the Gulf, the UK and the US, and mentoring at Omebly Academy. LinkedIn · GitHub