Imagine writing a Python script and having it run right inside your Excel cell — pulling in data, running machine-learning models, and visualising results without ever leaving the spreadsheet. That is no longer science fiction. Python in Excel is now fully available to Microsoft 365 subscribers worldwide, and in 2026 it has become one of the most transformative features in the Office suite.
Whether you are a data analyst, a financial modeller, or a marketer who wants more power than standard formulas can offer, this guide will walk you through everything you need to know to get started with Python in Excel today.
What Is Python in Excel?
Python in Excel lets you type Python code directly into a cell using the special =PY() function. When you press Ctrl+Enter, Excel sends your code to a secure Microsoft cloud environment powered by Anaconda, runs it, and returns the result back into your worksheet — all in real time.
The Anaconda distribution means you have immediate access to popular libraries such as pandas, NumPy, Matplotlib, scikit-learn, and hundreds of others. You do not need to install Python locally or manage virtual environments. Everything is handled by Microsoft.
Why This Changes Everything for Office Workers
Before Python in Excel, advanced data analysis required jumping between Excel and a separate Python IDE — exporting CSVs, running scripts, re-importing results. That workflow was slow and error-prone.
With Python in Excel in 2026, the entire workflow lives in one place:
- Clean messy data with pandas in seconds
- Build predictive models with scikit-learn directly on your spreadsheet data
- Create rich visualisations with Matplotlib or seaborn that embed as images in your sheet
- Perform statistical analysis that goes far beyond what Excel functions alone can handle
- Automate repetitive data-transformation tasks with a few lines of Python
How to Write Your First Python Formula in Excel
Getting started is easier than you might expect. Follow these steps:
- Open a blank Excel workbook in Microsoft 365 (desktop or web).
- Click on any empty cell — for example, cell D2.
- Type =PY( to open the Python editor pane.
- Enter your Python code. For a simple test, try: import pandas as pd; xl(‘A1:C10’, headers=True)
- Press Ctrl+Enter to run the code and return the result to your cell.
The xl() function is a special Excel-specific helper that lets your Python code reference ranges in your worksheet. It automatically converts the range into a pandas DataFrame, ready for manipulation.
Working With Your Spreadsheet Data in Python
The xl() function is your bridge between Excel data and Python. Here are the most common patterns:
Read a range: df = xl(‘A1:E100’, headers=True) — imports your data as a DataFrame
Filter rows: df[df[‘Revenue’] > 10000] — filter for high-revenue rows
Calculate new columns: df[‘Profit Margin’] = df[‘Profit’] / df[‘Revenue’] — create a derived column
Aggregate data: df.groupby(‘Region’)[‘Sales’].sum() — sum sales by region
Return results: The last expression in your =PY() cell is what gets returned to Excel
Visualising Data With Python in Excel
One of the most exciting features of Python in Excel is the ability to create charts that go far beyond Excel’s built-in charting. Using Matplotlib or seaborn, you can generate publication-quality visualisations embedded directly in your worksheet.
Here is a basic example that creates a bar chart from your data:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
df = xl(‘A1:B12’, headers=True)
ax.bar(df[‘Month’], df[‘Sales’])
ax.set_title(‘Monthly Sales 2026’)
plt.tight_layout()
fig
Press Ctrl+Enter and Excel embeds the chart directly in the cell. You can resize it just like a regular chart object.
Security and Privacy: What Happens to Your Data
A common question is: where does my data go when I run Python in Excel? Microsoft sends your data and code to a secure Azure environment operated by Anaconda. The environment is isolated per user and per session, so your data is never mixed with another user’s.
For sensitive or confidential data, review your organisation’s Microsoft 365 compliance settings before using Python in Excel. Enterprise customers can configure data residency policies through the Microsoft 365 admin centre.
Practical Use Cases for 2026
Here are some real-world scenarios where Python in Excel shines:
- Finance teams: Monte Carlo simulations for risk modelling without a separate Python environment
- Sales analysts: Predictive lead scoring models built on CRM data exported to Excel
- HR departments: Attrition analysis and workforce trend visualisation
- Marketing teams: Social media performance analysis with pandas aggregations
- Supply chain managers: Demand forecasting with time-series libraries like statsmodels
Tips for Getting the Most Out of Python in Excel
As you become more comfortable with Python in Excel, keep these best practices in mind:
- Use named ranges in Excel to make your xl() references more readable and maintainable
- Cache heavy computations — Python cells recalculate when dependencies change, so isolate expensive operations
- Combine with Copilot: use Microsoft 365 Copilot to suggest Python code for common data tasks
- Keep Python logic in Python cells and formatting in Excel cells — do not mix concerns
- Use the Python Diagnostics pane to debug errors without leaving Excel
Conclusion
Python in Excel is not just a feature update — it is a fundamental shift in what a spreadsheet can be. In 2026, the boundary between the Excel power user and the data scientist has never been thinner. Whether you want to clean data faster, build better models, or create more compelling visualisations, Python in Excel gives you the tools to do it all without leaving the application you already know.
Ready to start? Open Microsoft 365, create a new workbook, and type =PY( in any cell. Your Python journey in Excel begins right now.












