Learn  /  Guides

pandas for Excel users: VLOOKUP, pivot tables and SUMIFS in Python

Everything you already do in Excel, translated into Python, and why it scales better.

Guide10 min readUpdated 18 October 2026
PythonData analysis
All guides and cheat sheets

If you are comfortable in Excel, you already understand most of what pandas does. The difference is that a pandas script records every step, runs in seconds on millions of rows, and can be scheduled to run by itself. This guide maps familiar Excel tasks to their pandas equivalents.

Excel to pandas, at a glance

Filter
df[df["region"] == "North"]
IF / nested IF
.where(), np.select()
VLOOKUP / XLOOKUP
df.merge(lookup, on="id", how="left")
SUMIFS / COUNTIFS
df.groupby("region").agg(...)
Pivot table
pd.pivot_table(...)
Remove duplicates
df.drop_duplicates()
TRIM / PROPER
.str.strip().str.title()

Setting up

Terminal
uv add pandas openpyxl     # or: python -m pip install pandas openpyxl

New to Python environments? The uv guide covers setup in five minutes.

Opening a workbook

Python
import pandas as pd

sales = pd.read_excel("sales.xlsx", sheet_name="Orders")
products = pd.read_excel("sales.xlsx", sheet_name="Products")

sales.head()        # first five rows, like glancing at the top of a sheet
sales.info()        # column names, types and missing values
sales.describe()    # quick statistics for numeric columns

Filtering rows

Python
# Excel: filter the Region column to "North" and Amount greater than 100
north_big = sales[(sales["region"] == "North") & (sales["amount"] > 100)]

# Several values, like ticking boxes in a filter drop-down
selected = sales[sales["region"].isin(["North", "West"])]

Adding a calculated column

Python
sales["revenue"] = sales["quantity"] * sales["unit_price"]

# Excel IF: =IF(revenue > 500, "Large", "Standard")
sales["size"] = sales["revenue"].where(sales["revenue"] <= 500, "Large")
sales.loc[sales["revenue"] <= 500, "size"] = "Standard"

For several conditions, numpy.select replaces nested IFs cleanly:

Python
import numpy as np

conditions = [sales["revenue"] >= 1000, sales["revenue"] >= 500]
choices = ["Large", "Medium"]
sales["size"] = np.select(conditions, choices, default="Small")

VLOOKUP and XLOOKUP become merge

Python
# Bring product name and category into the sales table, matched on product_id
sales = sales.merge(
    products[["product_id", "product_name", "category"]],
    on="product_id",
    how="left",            # keep every sale, like VLOOKUP returning #N/A
    validate="many_to_one" # raises an error if products has duplicate IDs
)

missing = sales[sales["product_name"].isna()]   # your #N/A rows

SUMIFS and COUNTIFS become groupby

Python
by_region = (
    sales.groupby("region", as_index=False)
         .agg(revenue=("revenue", "sum"),
              orders=("order_id", "nunique"),
              avg_order=("revenue", "mean"))
         .sort_values("revenue", ascending=False)
)

Pivot tables

Python
pivot = pd.pivot_table(
    sales,
    index="region",
    columns="category",
    values="revenue",
    aggfunc="sum",
    fill_value=0,
    margins=True,           # adds the Grand Total row and column
    margins_name="Total"
)

Dates

Python
sales["order_date"] = pd.to_datetime(sales["order_date"], dayfirst=True)
sales["month"] = sales["order_date"].dt.to_period("M")
sales["weekday"] = sales["order_date"].dt.day_name()

monthly = sales.groupby("month", as_index=False)["revenue"].sum()
monthly["change_pct"] = monthly["revenue"].pct_change().mul(100).round(1)

Cleaning data

Each line below replaces a menu or formula you would use in Excel:

Python
sales = sales.drop_duplicates(subset="order_id")          # Remove Duplicates
sales["customer"] = sales["customer"].str.strip().str.title()  # TRIM and PROPER
sales["discount"] = sales["discount"].fillna(0)          # blanks become zero
sales = sales.rename(columns={"Cust Ref": "customer_ref"})

Saving back to Excel

Python
with pd.ExcelWriter("monthly_report.xlsx") as writer:
    by_region.to_excel(writer, sheet_name="By region", index=False)
    pivot.to_excel(writer, sheet_name="Pivot")
    monthly.to_excel(writer, sheet_name="Monthly", index=False)
One script, the whole report
read_excelopen the workbook
Cleanduplicates, blanks, names
merge and groupbylookups and totals
to_excelwrite the report

Check your understanding

1/3Which pandas method replaces VLOOKUP?

2/3What does validate="many_to_one" catch?

3/3How do you combine two filter conditions with AND?

Put these steps in one script and you have a report that rebuilds itself. The automation guide shows how to schedule it, and the pandas cheat sheet keeps every command above on a single page. Moving to pandas 3.0? Read Upgrading to pandas 3.0. Still living in Excel too? The Excel formulas cheat sheet covers XLOOKUP, FILTER and LET.

Alessandro Ecclesie AgazziWritten by Alessandro Ecclesie Agazzi, analytics engineer in London. Updated 30 September 2026. About me

Found this useful?

New guides and "what's new" explainers on data and AI land here regularly. Follow along on LinkedIn, or share this one with a colleague.