Excel vs Python pandas: Same Tasks Side by Side, and When to Use Each
Amir learned Excel first and now his manager wants Python. He takes the same Raja Coffee Roasters orders and asks the same question both ways. Excel: =SUMIFS(Orders[Amount],Orders[City],"Pune"). pandas: df[df["City"] == "Pune"]["Amount"].sum(). Both say ₹10,700. Most everyday analysis has a direct pair like this, so the real question is not which tool is better, but which one fits the job.
pandas is a Python library for working with tables (DataFrames). Each common Excel task has a pandas pair: filters are boolean masks, SUMIFS/PivotTables are groupby and pivot_table, XLOOKUP is merge, sorting is sort_values, Remove Duplicates is drop_duplicates. Use Excel for data that fits in a sheet and for interactive, visual work; use pandas for large files, repeatable scripted pipelines and version-controlled analysis. Python in Excel lets you run pandas inside a workbook on supported Microsoft 365 plans.
Download the practice file (vs-python-pandas.xlsx)
Excel file, 11 KB. It has the sample data used below. All numbers in this workbook are fictional teaching data, not real company figures.
Quick answer
- Read the file:
df = pd.read_excel("orders.xlsx", sheet_name="Orders")(needs the openpyxl package for .xlsx). - Filter rows with a boolean mask:
df[df["City"] == "Pune"]is the same as a filter on City. - Summarise with
df.groupby("City")["Amount"].sum(), the pandas SUMIFS or PivotTable. - Look up with
df.merge(customers, on="Customer", how="left"), the pandas XLOOKUP. - Cross-tab with
df.pivot_table(index="City", columns="Product", values="Amount", aggfunc="sum"). - Write back with
df.to_excel("out.xlsx", index=False).
Task-by-task mapping
| Task | Excel | pandas |
|---|---|---|
| Open data | File > Open, Get Data | pd.read_excel("f.xlsx", sheet_name="Orders"), pd.read_csv("f.csv") |
| Look at the top rows | Scroll | df.head() |
| Filter | Filter button, FILTER | df[df["City"] == "Pune"] |
| Two conditions | (c1)*(c2) in FILTER, SUMIFS with two pairs | df[(df["City"] == "Pune") & (df["Amount"] >= 1000)] |
| Sort | Sort, SORT | df.sort_values("Amount", ascending=False) |
| Remove duplicates | Remove Duplicates, UNIQUE | df.drop_duplicates() |
| New column | Formula filled down | df["Band"] = np.where(df["Amount"] >= 1500, "Large", "Small") |
| Sum by group | SUMIFS, PivotTable | df.groupby("City")["Amount"].sum() |
| Cross-tab | PivotTable with Rows and Columns | df.pivot_table(index=..., columns=..., values=..., aggfunc="sum") |
| Look up from another table | XLOOKUP, Power Query Merge | df.merge(cust, on="Customer", how="left") |
| Stack two tables | VSTACK, Power Query Append | pd.concat([a, b]) |
| Blanks | Blank cells, ISBLANK | NaN, df.isna(), df.fillna(0) |
| Save | Save As | df.to_excel("out.xlsx", index=False) |
The pandas documentation has its own page on this, *Comparison with spreadsheets*, which maps Excel features to pandas: pandas.pydata.org: Comparison with spreadsheets.
Side by side on the same data
We ran every pandas line below on the practice file's Orders table and checked that Excel returns the same numbers.
| Task | pandas | Excel | Answer |
|---|---|---|---|
| Total sales in Pune | df[df["City"] == "Pune"]["Amount"].sum() | =SUMIFS(Orders[Amount],Orders[City],"Pune") | ₹10,700 |
| Different customers | df["Customer"].nunique() | =COUNTA(UNIQUE(Orders[Customer])) | 8 |
| Largest order | df["Amount"].max() | =MAX(Orders[Amount]) | ₹3,200 |
| Average quantity | df["Qty"].mean() | =AVERAGE(Orders[Qty]) | 2.71 |
| Rows in the table | len(df) | =ROWS(Orders[Order ID]) | 24 |
# groupby = SUMIFS / COUNTIFS / AVERAGEIFS by city
df.groupby("City")["Amount"].agg(["sum", "count", "mean"])
# merge = XLOOKUP (how='left' keeps every order)
df.merge(customers[["Customer", "Segment"]], on="Customer", how="left")
# pivot_table = PivotTable / SUMIFS grid
df.pivot_table(index="City", columns="Product", values="Amount", aggfunc="sum", fill_value=0)
| City | sum | count | mean |
|---|---|---|---|
| Kolhapur | ₹3,900 | 3 | ₹1,300 |
| Nagpur | ₹6,440 | 4 | ₹1,610 |
| Nashik | ₹4,700 | 4 | ₹1,175 |
| Pune | ₹10,700 | 8 | ₹1,338 |
| Solapur | ₹5,800 | 5 | ₹1,160 |
After a left merge, Ruhi's orders have no segment because she is not in the Customers table. pandas shows NaN; the Excel XLOOKUP shows "(no match)" because we set that as its if_not_found value.
Where each tool is stronger
| Point | Excel | pandas |
|---|---|---|
| Size | Up to 10,48,576 rows by 16,384 columns per worksheet (Microsoft's published limit) | Limited by your computer's memory; the pandas docs have a guide on scaling to large datasets |
| Seeing the data | You see every cell and change it directly | You see data when you print or display it |
| Repeating the work | Re-do steps, or record them in Power Query or a macro | Re-run the script on new files; every step is written down |
| Checking changes | Hard to compare two versions of a workbook | Scripts are plain text and work well with version control such as Git |
| Charts and sharing | Built-in charts, easy to send to anyone with Excel | Charts with libraries such as Matplotlib; readers need the output, not Python |
| Learning curve | Most office users already know it | You need to learn Python first |
Rule of thumb: if the file opens comfortably and the task is one-off, stay in Excel. If the data is bigger than a sheet, arrives every week in the same shape, or needs joins across many files, script it in pandas.
Python in Excel: both in one workbook
Python in Excel lets you type =PY( in a cell and run Python, including pandas, on data from the workbook; the code runs in Microsoft's cloud. According to Microsoft's *Python in Excel availability* page, it is available to Enterprise and Business users on Windows (Current Channel from Version 2408), on Excel for the web, and on Excel for Mac (Current Channel from Version 16.96), with preview access for Family and Personal users. It needs a paid Microsoft 365 licence with desktop apps. Check the page for your plan before you build on it: Python in Excel availability.
Ravindra Bagale's Tip
Learn pandas by repeating a job you already do in Excel. Take one weekly report, write each step as a pandas line next to the Excel step, and check that every total matches. When they match for three weeks in a row, you can trust the script.
Ravindra Bagale's Tip – मराठी
Excel मध्ये आधीच करत असलेले काम pandas मध्ये पुन्हा करून pandas शिका. एक weekly report घ्या, प्रत्येक Excel step शेजारी pandas ची line लिहा, आणि प्रत्येक total जुळतो का ते तपासा. सलग तीन आठवडे जुळले की script वर विश्वास ठेवू शकता.
Ravindra Bagale's Tip – हिंदी
Excel में जो काम पहले से करते हैं, उसे pandas में दोबारा करके pandas सीखिए। एक weekly report लीजिए, हर Excel step के पास pandas की line लिखिए, और देखिए कि हर total मिलता है या नहीं। लगातार तीन हफ्ते मिल जाए तो script पर भरोसा कर सकते हैं।
Practice task
- Write the pandas line for
=COUNTIFS(Orders[City],"Nashik")and check it against the sheet. - Write the Excel formula for
df["Qty"].sum(). - On the pandas vs Excel sheet, add a row for average order value by Product with AVERAGEIFS, then write the groupby that matches.
- If you have Python, run
pd.read_excelon the practice file and repeat the groupby. Do your numbers match the sheet? - Which of your weekly Excel tasks would you move to pandas first, and why?
Learn it properly
Course lessons:
- 29.1 What Python in Excel Is: Availability and Licensing
- 29.5 pandas groupby in Excel: Totals, Several Measures and a Pivot Table
- 3.2 SUM, SUMIF and SUMIFS
- 4.6 XLOOKUP Basics and if_not_found
- 7.1 Creating a PivotTable
Related guides: Excel vs SQL: Term-by-Term Mapping with Side-by-Side Examples · PivotTable vs GROUPBY and PIVOTBY: Which Should You Use in Excel? · FILTER Function · SUMIF and SUMIFS
Frequently asked questions
Should analysts learn pandas or Excel first?
Excel first for most office roles: it is what colleagues use and it teaches the ideas (filters, grouping, lookups). Add pandas when files get large or reports repeat every week.
Can pandas read my Excel files?
Yes. pandas.read_excel reads .xlsx files (it uses an engine such as openpyxl) and DataFrame.to_excel writes them.
What is the pandas version of a PivotTable?
DataFrame.pivot_table, or groupby followed by unstack. Both are in the official pandas documentation.
Do I need Python installed to use Python in Excel?
No. Python in Excel runs in Microsoft's cloud, but you need a supported Microsoft 365 plan and version.