If you already know Excel well, you know more about data analysis than you think. Filters, VLOOKUP, SUMIFS and PivotTables all have direct equivalents in Python’s pandas library, and once you see them side by side, the code stops looking scary. This guide on pandas for Excel users walks through 10 everyday tasks you probably do every week, shows the Excel way you already know, and gives you short, tested pandas code for each. By the end you will be able to open a workbook, clean it, summarize it and save a multi-sheet report with one script.
Why bother when Excel works? Because a script repeats the same steps exactly every time, handles files far larger than Excel’s row limit, and can process a whole folder of workbooks in seconds. I use Python alongside Excel for exactly these jobs.
Getting set up
Install a recent version of Python 3 from python.org, then open a terminal (Command Prompt on Windows) and install pandas plus openpyxl, the library pandas uses to read and write .xlsx files:
pip install pandas openpyxl
You can write code in any editor. Many Excel users like VS Code with the Jupyter extension or JupyterLab, because you run one small block at a time and see the result as a table underneath, which feels a lot like working in a spreadsheet.
The examples use a workbook called sales.xlsx with two sheets. Sales has OrderID, OrderDate, Customer, ProductID, Region, Qty and Price. Products has ProductID, ProductName and Category.
Open, inspect and clean your data
1. Open a workbook (instead of File, Open)
import pandas as pd
import numpy as np
sales = pd.read_excel("sales.xlsx", sheet_name="Sales")
products = pd.read_excel("sales.xlsx", sheet_name="Products")
# CSV files: pd.read_csv("sales.csv")
Each sheet becomes a DataFrame, which is pandas’ version of a table: named columns, numbered rows. The script must be in the same folder as the file, or you can give the full path.
2. Look at the data (instead of scrolling)
print(sales.head()) # first 5 rows
sales.info() # column names, data types, blank counts
print(sales.describe()) # count, mean, min, max of number columns
info() is the one to check first. If a date or number column shows as text (object or str), it needs cleaning before you calculate anything.
3. Clean text, dates and duplicates (instead of TRIM, PROPER and Remove Duplicates)
# Trim spaces and fix capitalization, like =PROPER(TRIM(A2))
sales["Customer"] = sales["Customer"].str.strip().str.title()
# Turn text dates such as 15/02/2026 into real dates (day first)
sales["OrderDate"] = pd.to_datetime(sales["OrderDate"], dayfirst=True)
# Data, Remove Duplicates (rows identical in every column)
sales = sales.drop_duplicates()
One caution: str.title() turns “Beta LLC” into “Beta Llc”, just like Excel’s PROPER does. Use it only on columns where that is acceptable.
Everyday formula tasks in pandas
4. Add a calculated column and an IF
# Like =D2*E2 filled down
sales["Total"] = sales["Qty"] * sales["Price"]
# Like =IF(H2>=1000, "Large", "Small")
sales["Size"] = np.where(sales["Total"] >= 1000, "Large", "Small")
Notice there is no “fill down”. An operation on a column applies to every row at once.
5. Filter rows (instead of AutoFilter)
# Region is West AND Total over 500
west_big = sales[(sales["Region"] == "West") & (sales["Total"] > 500)]
# Customer is one of a list
some = sales[sales["Customer"].isin(["Acme Corp", "Beta Llc"])]
Use & for AND and | for OR, and wrap each condition in brackets. Forgetting the brackets is the most common error at this step.
6. Sort (instead of Data, Sort)
# Region A to Z, then Total largest first
sales = sales.sort_values(["Region", "Total"], ascending=[True, False])
7. VLOOKUP with merge
# Bring ProductName and Category from Products into Sales
sales = sales.merge(products, on="ProductID", how="left")
# Rows where the lookup failed (the #N/A rows in Excel)
missing = sales[sales["ProductName"].isna()]
how="left" keeps every sales row, exactly like VLOOKUP does. A big advantage over VLOOKUP: every matching column comes across in one step, and nothing breaks if someone inserts a column in the Products sheet.
Summaries, PivotTables and reports
8. SUMIFS and COUNTIFS with groupby
summary = sales.groupby("Customer").agg(
Orders=("OrderID", "count"), # COUNTIFS
Revenue=("Total", "sum"), # SUMIFS
AvgOrder=("Total", "mean"), # AVERAGEIFS
).reset_index()
This gives one row per customer with three summary columns. Group by several columns, for example ["Region", "Customer"], for the equivalent of SUMIFS with two criteria.
9. PivotTable with pivot_table
sales["Month"] = sales["OrderDate"].dt.to_period("M").astype(str) # 2026-01
pivot = sales.pivot_table(
index="Region", # Rows area
columns="Month", # Columns area
values="Total", # Values area
aggfunc="sum",
fill_value=0, # show 0 instead of blank
margins=True, # grand totals
margins_name="Total",
)
10. Combine a folder of files and save a multi-sheet report
from pathlib import Path
# Stack every CSV in the "monthly" folder, noting the file name
files = Path("monthly").glob("*.csv")
combined = pd.concat(
[pd.read_csv(f).assign(SourceFile=f.name) for f in files],
ignore_index=True,
)
# Write several DataFrames to one workbook, one sheet each
with pd.ExcelWriter("sales_report.xlsx") as writer:
summary.to_excel(writer, sheet_name="Summary", index=False)
pivot.to_excel(writer, sheet_name="By Month")
sales.to_excel(writer, sheet_name="Clean Data", index=False)
This is the task that usually convinces people. Fifty monthly files take the same few seconds as two, and the report is rebuilt from scratch every time, so there is no stale data left over from last month.
Quick reference: Excel to pandas
| Excel | pandas |
|---|---|
| Open a sheet | pd.read_excel(file, sheet_name=...) |
| AutoFilter | df[df["Col"] == value] |
| Sort | df.sort_values("Col") |
| IF | np.where(condition, yes, no) |
| VLOOKUP / XLOOKUP | df.merge(other, on="Key", how="left") |
| SUMIFS / COUNTIFS | df.groupby("Col").agg(...) |
| PivotTable | df.pivot_table(...) |
| Remove Duplicates | df.drop_duplicates() |
| Save As | df.to_excel(file, index=False) |
The pandas team also keeps an official comparison with spreadsheets page that is worth bookmarking.
Common mistakes Excel users make in pandas
- Forgetting to assign the result.
sales.sort_values("Total")on its own changes nothing. Writesales = sales.sort_values("Total"). - Using “and” instead of “&” in filters. Python’s
anddoes not work on whole columns. Use&and brackets around each condition. - Saving the index. Without
index=False,to_exceladds an extra column of row numbers. - Writing over a workbook that is open. On Windows, saving to a file open in Excel fails with a permission error. Close it first.
- Expecting formatting. pandas writes values, not colors, column widths or formulas. Format the output with openpyxl, or paste the data into a formatted template.
Frequently asked questions
Do I need to know programming to use pandas?
No. If you can write nested Excel formulas, you can learn the basics of pandas in a few evenings. Start by repeating one task you already do in Excel.
Can pandas handle more than a million rows?
Yes. Pandas is limited by your computer’s memory, not by a fixed row count, so files of several million rows are usually fine on a normal laptop.
Will pandas keep my Excel formulas?
No. read_excel reads the calculated values, and to_excel writes values only. If you need live formulas in the output, write them with openpyxl after pandas has done the heavy lifting.
Should I use Python in Excel instead?
Python in Excel, available in some Microsoft 365 plans, runs pandas inside a cell. It is useful for analysis inside one workbook, but a standalone script is better for processing many files or running on a schedule.
Want a Python tool built for you?
If you have a repetitive Excel process that has outgrown formulas and macros, I build Python tools that do it in seconds, like the Python audit dashboard in my portfolio. See my Python automation service or get an instant quote.
