Python in Excel lets you type Python code straight into a cell and get the result back in your spreadsheet. You don’t install anything: the code runs in Microsoft’s cloud with pandas, matplotlib, seaborn and other Anaconda libraries ready to use.
It’s the easiest way for Excel users to try data analysis, charts and statistics that would be painful with formulas alone.
This guide covers who has it, how to write your first Python formula, how xl() pulls in your data, which libraries you can use, the keyboard shortcuts, premium compute and its price, what happened to Copilot’s Python analysis in 2026, and how to fix every Python error.
Short answer: In Excel for Windows, Mac or the web, select a cell and go to Formulas > Insert Python, or type =PY and press Tab (shortcut Ctrl+Alt+Shift+P). Write your code, use xl("A1:D100", headers=True) to read cells, and press Ctrl+Enter to run it.
- Who has it: generally available for Microsoft 365 Business and Enterprise; still a preview for Family and Personal.
- Not on: iPhone, iPad or Android, and not offline.
- Cost: standard compute is included; a premium compute add-on costs £18.48 per user per month in the UK.
- Copilot: Copilot’s “advanced analysis with Python” has been retired.
What Is Python in Excel?
Python in Excel is a built-in Excel feature that runs Python code from a cell in the Microsoft cloud and returns the result to your sheet.
Microsoft’s help page says the calculations run in the Microsoft Cloud with a core set of Anaconda libraries, and that you don’t need a local Python install. Anything you’ve customised on your own computer isn’t used.
That means an internet connection is required. There’s no offline mode.
Python cells sit alongside normal formulas. You can feed them ranges and tables, and use their results in charts, formulas and conditional formatting.
Who Can Use Python in Excel?
| Plan | Windows | Mac | Web |
|---|---|---|---|
| Business and Enterprise | Generally available (Current Channel 2408 or later) | Current Channel 16.96 or later | Available |
| Family and Personal | Preview (Current Channel 2405 or later) | Preview via Insider Beta Channel 16.95+ | Preview |
| Education | Preview via Insider Current Channel (Preview) | – | – |
Other rules from Microsoft’s availability page:
- You need a paid Microsoft 365 licence that includes the desktop apps. Free and one-time-purchase (perpetual) Office licences don’t qualify.
- Device-based licences and shared computer activation aren’t supported.
- Connected experiences must be turned on in your privacy settings.
- iPad, iPhone and Android can open the workbook, but Python cells show an error when they recalculate.
Not sure which plan you’re on? Our Microsoft 365 Premium vs Personal vs Family comparison explains the consumer plans.
How to Write Your First Python Formula
- Click an empty cell.
- Go to Formulas > Insert Python, or type =PY, press the Down arrow and then Tab. You can also press Ctrl+Alt+Shift+P.
- The cell shows a green PY badge. Type your code in the formula bar. Press Enter for a new line.
- Press Ctrl+Enter to run it.
- Expand the formula bar with Ctrl+Shift+U, or open the full code editor with Ctrl+Alt+Shift+F2 for longer scripts.
Try this to test it works:
import sys
sys.version
The last line of a Python cell is what gets returned to the sheet, just like a notebook.
Excel runs Python cells in row-major order: left to right across a row, then down, sheet by sheet in tab order. Define a variable in a cell above (or to the left of) any cell that uses it.
Reading Your Data with xl()
The xl() function brings Excel ranges, tables, names and Power Query results into Python.
| Code | What it reads |
|---|---|
xl("A1") |
One cell |
xl("B1:C4") |
A range, as a DataFrame |
xl("A1:D100", headers=True) |
A range with the first row as column names |
xl("Sales[#All]", headers=True) |
A whole Excel table called Sales |
xl("MyName") |
A named range |
You can’t read files from your computer or the web with pandas.read_csv or read_excel. Microsoft’s guidance is to bring outside data in with Data > Get & Transform (Power Query) first, then reference the query with xl().
Python Object vs Excel Value
| Output type | What you see | Use it when |
|---|---|---|
| Excel value | Numbers and text spilled into cells | You want to chart, format or use the results in formulas |
| Python object | A card icon in the cell you can preview | Other Python cells will reuse the DataFrame or model |
Switch with the Python output menu next to the formula bar, by right-clicking the cell and choosing Python Output, or with Ctrl+Alt+Shift+M. Microsoft recommends Python object when later cells build on the result.
Five Useful Examples
1. Summary statistics
df = xl("Sales[#All]", headers=True)
df.describe()
2. Group and total
df.groupby("Region")["Revenue"].sum()
3. A chart with seaborn
sns.barplot(data=df, x="Region", y="Revenue")
Plots appear in the cell. Press Ctrl+Alt+Shift+C to turn one into a floating plot you can move and resize.
4. Clean messy text
df["Email"] = df["Email"].str.strip().str.lower()
df
5. A quick regression
model = sm.OLS(df["Revenue"], sm.add_constant(df["AdSpend"])).fit()
model.params
If you’re more comfortable asking in plain English, our Copilot in Word, Excel and PowerPoint guide covers what Copilot can do in a sheet without code.
Libraries You Can Use
These are imported automatically in every workbook:
| Library | Alias | Used for |
|---|---|---|
| pandas | pd | Tables and data cleaning |
| NumPy | np | Maths and arrays |
| matplotlib.pyplot | plt | Charts |
| seaborn | sns | Statistical charts |
| statsmodels | sm | Statistics and regression |
You can import other libraries from Anaconda’s curated list, for example from bs4 import BeautifulSoup or scikit-learn. Put imports on the first sheet so they run first. You can’t pip install your own packages, and libraries can’t make network requests or read local files.
Default imports live in Formulas > Python > Initialization. Microsoft warns that removing the built-in statements may cause errors, so add to the list rather than deleting.
Keyboard Shortcuts
| Shortcut | What it does |
|---|---|
| Ctrl+Alt+Shift+P | Start a Python formula (same as =PY) |
| Ctrl+Enter | Run (commit) the Python formula |
| Ctrl+Alt+Shift+M | Switch output between Python object and Excel value |
| Ctrl+Alt+Shift+F2 | Open the code editor |
| Ctrl+Alt+Shift+F9 | Reset the Python runtime |
| Ctrl+Shift+U | Expand the formula bar |
| Ctrl+Shift+F5 | Open a Python object’s card |
| Ctrl+Alt+Shift+C | Make a plot a floating plot |
Standard vs Premium Compute and Price
| Standard | Premium (add-on) | |
|---|---|---|
| Cost | Included with Microsoft 365 | £18.48 per user per month (£184.80 per year), excl. VAT, on Microsoft’s UK page |
| Speed | Normal | Faster |
| Calculation modes | Automatic only | Automatic, Partial and Manual |
| Who can buy | – | Business and Enterprise plans with Excel for Windows |
Qualifying subscriptions also get a limited monthly allowance of premium compute, after which they drop back to standard until the next month. At launch in September 2024, The Register reported the add-on at $24 per user per month in the US; check Microsoft’s page for your region’s current price.
Admins buy the add-on in the Microsoft 365 admin centre under Billing > Your products. It can take 24 to 72 hours to apply; if it doesn’t show, go to File > Account > Update License.
Python and Copilot in 2026
Copilot’s “advanced data analysis with Python” in Excel has been retired.
Microsoft’s Excel blog said on 24 February 2026 that App Skills was being replaced by Copilot Chat and Agent Mode, and that Advanced Analysis with Python “is not yet available in Copilot Chat or Agent Mode”. The support article for the old feature now says its content is no longer available.
Python in Excel itself is unaffected. You just write the code yourself, or ask Copilot Chat or another AI to draft it and paste it into a Python cell.
Is Python in Excel Safe?
- Code runs in Microsoft’s cloud in hypervisor-isolated containers, one per workbook.
- Microsoft says the container “doesn’t have network access” and has no access to “your computer, devices, or account”.
- “Data isn’t persisted”: containers are destroyed after use.
- Files opened in Protected View don’t run Python formulas.
- Admins can show a warning or block Python in files from others with the
PythonFunctionWarningspolicy (0 = no warning, 1 = prompt, 2 = block).
The main thing to remember: your data is sent to Microsoft’s cloud for the calculation, so follow your company’s rules for sensitive workbooks.
Python in Excel Errors and Fixes
| Error | What it means | Fix |
|---|---|---|
| #BUSY! | Still calculating in the cloud | Wait; if it lasts over 60 seconds, reset the runtime (Formulas > Python > Reset runtime or Ctrl+Alt+Shift+F9) |
| #CONNECT! | Lost the cloud connection | Check your internet and reset the runtime |
| #CALC! | Uses a volatile value like RAND, or over 100 MB of data | Remove the volatile reference or reduce the data |
| #PYTHON! | Error in your code, often syntax | Right-click the cell > Diagnostics for this cell |
| #BLOCKED! | Python not enabled, connected experiences off, or a device/shared licence | Turn on connected experiences; use a user-based licence |
| #SPILL! | Output range isn’t empty | Clear the cells where results need to go |
| #TIMEOUT! | Took too long | Rerun, or raise File > Options > Advanced > Python Formula Timeout |
| #UNKNOWN! | Excel version doesn’t support Python | Update Excel |
If there’s no Insert Python button at all, check your plan and channel against the availability table and update Excel.
Frequently Asked Questions
How do I enable Python in Excel?
There’s nothing to install. On a supported Microsoft 365 plan, go to Formulas, Insert Python, or type =PY in a cell and press Tab.
Is Python in Excel free?
Standard compute is included with eligible Microsoft 365 subscriptions. Faster premium compute is a paid add-on for business plans.
Does Python in Excel work offline?
No. The code runs in Microsoft’s cloud, so you need an internet connection.
Can I install my own Python packages?
No. You can import libraries from Anaconda’s curated list, but pip installs aren’t supported.
How do I read Excel data in Python?
Use the xl() function, for example xl(“A1:D100”, headers=True) or xl(“Sales[#All]”, headers=True) for a table.
Why does my Python cell show #BUSY!?
It’s still calculating in the cloud. If it lasts more than a minute, reset the runtime with Ctrl+Alt+Shift+F9.
Can Copilot write Python in Excel for me?
Copilot’s built-in Python analysis was retired in 2026. You can still ask Copilot Chat or another AI for code and paste it into a Python cell.
Final Thoughts
Python in Excel is the gentlest way to start with Python: no setup, your data is already there, and pandas and seaborn are one line away. Start with describe() and a chart, then build up.
Business users get the full release; Family and Personal subscribers should check they’re on the right channel. Premium compute is only worth paying for if you hit #BUSY! often or need manual calculation.



