Guides

How to Use Python in Excel

Arkzero ResearchApr 7, 20267 min read

Last updated Apr 7, 2026

Python in Excel is a Microsoft 365 feature that runs Python code directly in spreadsheet cells using a cloud-based Anaconda environment. No local Python installation is required. It gives Excel users access to pandas, matplotlib, NumPy, and scikit-learn through the =PY() formula. The feature is available on Excel for Windows, Mac, and the web for active Microsoft 365 subscribers. All execution happens in Microsoft's cloud, so results are returned to the worksheet without any setup beyond opening Excel.
How to Use Python in Excel - tutorial guide

Python in Excel lets you run Python code inside spreadsheet cells using Microsoft's cloud infrastructure. No local Python installation is required. You get access to pandas, matplotlib, NumPy, and other Anaconda libraries through the =PY() formula. To start, open Excel for Microsoft 365 on Windows or Mac, navigate to the Formulas tab, and select Insert Python, or type =PY( into any cell.

What Python in Excel Can Do

Python in Excel connects your spreadsheet data to a full Python environment running in Microsoft's cloud. When you enter a Python formula, Excel sends the data and code to an Anaconda-managed container, executes it, and returns the result as a value, a DataFrame object, or a rendered chart.

This closes the gap between what Excel handles natively and what data analysts typically need Python for: cleaning messy datasets, running statistical models, generating correlation matrices, or producing publication-quality charts. The environment includes the complete Anaconda distribution, which covers over 1,500 scientific Python packages according to Microsoft's documentation.

For teams that already work in Excel, this means significantly less friction. An analyst can apply a pandas groupby aggregation, run a logistic regression with scikit-learn, or plot a seaborn heatmap without leaving the spreadsheet they were already working in. This is particularly useful for quarterly reporting workflows where the final deliverable is an Excel file and switching tools mid-analysis creates unnecessary overhead.

Requirements Before You Start

Python in Excel is available on Microsoft 365 Personal, Family, Business, and Enterprise plans. It is not included with standalone Office licenses such as Office 2021 or Office 2019. You need an active Microsoft 365 subscription.

As of 2026, the feature runs on Excel for Windows, Excel for Mac, and Excel for the web. It is not available on mobile devices including iPad, iPhone, or Android.

To verify your eligibility: open Excel, go to the Formulas tab, and look for the Insert Python button in the ribbon. If it is absent, your Office installation may need updating. Update via File, Account, then Update Options to ensure you are running version 2406 or later.

Python in Excel requires an active internet connection because all execution happens on Microsoft's servers. If you work offline or on a corporate network with outbound restrictions, Python cells will not recalculate.

How to Write Your First Python Formula

Select an empty cell. Type =PY( and press Tab to confirm. A dedicated code editor appears below the formula bar, giving you a multi-line Python input area.

To reference existing spreadsheet data inside Python, use the xl() function. For example, if your sales data occupies the range A1:C500, reference it as follows:

import pandas as pd
df = xl("A1:C500", headers=True)
df.describe()

This returns a summary statistics DataFrame directly into the cell. By default, Excel displays a collapsed card icon. Click it to expand the DataFrame as a table into adjacent cells.

Set the output type using the formula bar dropdown: Card (the default), Array (spills values into adjacent cells), or Plot (for charts). Most practical use cases start with Array to push results directly into your spreadsheet layout.

Practical Examples for Business Analysis

Summarize sales by region:

df = xl("A1:D1000", headers=True)
df.groupby("Region")["Revenue"].sum().reset_index()

This collapses a thousand-row table into a grouped summary. No pivot table configuration required. Useful when you need to share a clean summary with stakeholders who are not familiar with pivot table mechanics.

Find correlation between two columns:

df = xl("B1:C500", headers=True)
df.corr()

The output is a correlation matrix. Useful for checking whether ad spend actually tracks with sales, or whether two reported metrics are measuring essentially the same thing.

Flag statistical outliers:

df = xl("A1:B300", headers=True)
mean = df["Sales"].mean()
std = df["Sales"].std()
df["outlier"] = df["Sales"] > mean + 2 * std
df

This appends an outlier flag column to your data. Spill the result into an adjacent range and apply native Excel conditional formatting on top of it for immediate visual review.

Working with Charts and Visualizations

Python in Excel renders matplotlib and seaborn plots directly inside the spreadsheet. Change the formula output mode to Plot to display charts inline.

A histogram of customer order values:

import matplotlib.pyplot as plt
df = xl("A1:B1000", headers=True)
fig, ax = plt.subplots()
ax.hist(df["Order Value"], bins=30, color="#0055ff")
ax.set_xlabel("Order Value ($)")
ax.set_ylabel("Count")
plt.tight_layout()
fig

The chart appears as an embedded image in the cell. Resize it like any Excel chart. It recalculates automatically when the underlying data changes.

One difference from native Excel charts: Python plots do not link to slicers or pivot table filters. They recalculate when source data changes, but they do not respond to interactive filter controls. For dashboards where end users apply filters, use native Excel chart types for interactive views and reserve Python charts for analytical outputs.

Limitations to Know Before Relying on It

No external file imports. The common pandas functions pandas.read_csv() and pandas.read_excel() are blocked inside Python in Excel. You cannot pull data from a file path or external URL. All data must come through Power Query or by referencing existing Excel table ranges via xl(). This is the most common friction point for users migrating from a standard Python workflow.

Cloud execution adds latency. Each =PY() formula recalculates by sending code to Microsoft's servers. On large datasets or complex operations, this introduces a delay of several seconds. For spreadsheets with heavy computation across many Python cells, switching to Manual calculation mode reduces recalculation overhead. Access this via Formulas, Calculation Options, Manual.

No cross-cell state. Variables defined in one =PY() cell are not available in another. Each formula runs in isolation. To share a computed DataFrame across multiple output cells, structure your analysis to flow from a single parent formula, or use Python's xlwings-style approach of returning arrays that downstream cells reference.

Row limits apply. Excel's 1,048,576-row limit applies to the source ranges you pass to xl(). Python itself can handle larger data, but your input cannot exceed the spreadsheet's capacity.

If your workflow requires connecting live databases, running multi-step pipelines, or analyzing data too large to load into a spreadsheet, VSLZ AI handles this from a plain-English prompt after a file upload, without any formula syntax or environment configuration.

What This Means for Everyday Analysts

Python in Excel is a practical upgrade for anyone who already works in Excel and wants more analytical power without switching tools. A survey conducted by Microsoft in late 2025 found that over 60% of Excel users who tried Python in Excel used it weekly within the first month, primarily for data cleaning and chart generation tasks that previously required exporting to a separate Python environment.

The setup is minimal: an active Microsoft 365 subscription, Excel version 2406 or later, and an internet connection. The core workflow of referencing data with xl(), applying pandas or scikit-learn operations, and returning results as a table or chart takes about five minutes to learn.

The main constraints to plan around are the block on external file imports, the latency on large datasets, and the lack of cross-cell variable persistence. For analysis that fits within a single connected session and uses data already in the spreadsheet, Python in Excel removes most of the traditional barrier between Excel and Python workflows.

FAQ

What Microsoft 365 plan do I need for Python in Excel?

Python in Excel is available on Microsoft 365 Personal, Family, Business Basic, Business Standard, and Enterprise plans. It is not available with standalone Office licenses such as Office 2021 or Office 2019. You need an active subscription. To verify, open the Formulas tab in Excel and look for the Insert Python button.

Do I need to install Python to use Python in Excel?

No. Python in Excel runs entirely in Microsoft's cloud using an Anaconda-managed environment. You do not need to install Python, pip, or any packages on your local machine. All libraries including pandas, matplotlib, NumPy, and scikit-learn are available by default through the cloud environment.

What Python libraries are available in Python in Excel?

Python in Excel provides access to the Anaconda distribution, which includes over 1,500 Python packages. Core data analysis libraries including pandas, NumPy, matplotlib, seaborn, and scikit-learn are available. You cannot install additional packages using pip, as the environment is managed by Microsoft and Anaconda. The full list of available packages is documented in Microsoft's official Python in Excel library reference.

Why does pandas.read_csv not work in Python in Excel?

Common external data import functions like pandas.read_csv() and pandas.read_excel() are blocked in Python in Excel for security reasons. Python cells cannot access local file paths or external URLs. Instead, use Power Query to import external files into the spreadsheet first, then reference those ranges using the xl() function inside your Python formula.

Can Python in Excel handle large datasets?

Python in Excel is subject to Excel's 1,048,576-row limit on source ranges passed to xl(). For analysis within those limits, it handles reasonably large datasets, though cloud execution adds latency on complex operations. For datasets exceeding Excel's capacity or requiring live database connections, a dedicated data analysis platform is more appropriate.

Related

OpenMetadata data catalog interface showing database schema discovery
Guides

How to Set Up OpenMetadata for Data Discovery

OpenMetadata is an open-source data catalog that gives teams a single place to discover, document, and govern their data assets. Setting it up takes under 30 minutes using Docker: spin up the containers, log into the UI at localhost:8585, then connect your first data source using one of 90+ pre-built connectors. Once ingestion runs, every table, column, and owner is searchable and lineage-linked across your entire stack.

Arkzero Research · Apr 29, 2026
Streamlit logo on a clean white background
Guides

How to Build a Data Dashboard with Streamlit

Streamlit is an open-source Python library that turns a script into a shareable web dashboard without any front-end code. Install it with pip, write a Python file that loads your CSV with pandas, add sidebar widgets for filtering, and render interactive charts with Plotly. Push the file to GitHub, connect it to Streamlit Community Cloud, and anyone with the URL can view live results. No server configuration required.

Arkzero Research · Apr 29, 2026
Airbyte Cloud data integration platform
Guides

How to Set Up Airbyte Cloud for Data Syncing

Airbyte Cloud is a managed data integration platform that syncs data from SaaS tools, databases, and APIs into a central warehouse without requiring Docker, infrastructure, or engineering resources. A free 30-day trial lets you connect sources like Salesforce, HubSpot, Stripe, or Google Sheets to destinations like BigQuery, Snowflake, or Postgres in minutes. This guide walks through the full setup from account creation to your first automated sync.

Arkzero Research · Apr 29, 2026