Combining Python and Excel It has become one of the most interesting topics for those who work daily with spreadsheets and need to get the most out of their data. For years, the only way to unite these two worlds was through external libraries, APIs, and some patience. Now Microsoft has made its move and is integrating Python directly into Excel, completely changing the game.
In this guide you will see How to use Python in ExcelWe'll cover exactly what Microsoft's official integration offers, how to enable it, what you can do with it, and what its current limitations are. We'll also review the main classic library-based alternatives, such as... openpyxlpandas or xlwings. And even AI-powered tools that allow you to automate Excel without writing a single line of code.
What exactly is Python in Excel?
When we talk about Python in Excel We're referring to the official functionality that Microsoft has incorporated into Excel, which allows you to write Python code directly into cells, just as if you were entering a formula. That code is then sent to the... microsoft cloudIt runs there with a standard version of Python and the results are returned to your workbook as values, tables, graphs, or Python objects.
For this new environment, Microsoft relies on AnacondaIt provides a set of Python libraries widely used in data science and statistical analysis. The goal is to perform everything from complex data cleaning to advanced statistical modeling without leaving Excel.
The most striking thing is that You don't need to install Python locally Nor do you have to manage virtual environments on your computer. The engine runs in the cloud, with a standard and secure configuration, fully managed by Microsoft. This greatly simplifies things for business users who don't want to deal with installations and dependencies.
This approach makes it possible for you to combine the classic Excel ecosystem (Tables, formulas, pivot tables, charts) with the full power of the Python ecosystem (DataFrames, advanced visualizations, statistical models, automation, etc.). All within the same book.
Availability and platforms where you can use it
The integration of Python in Excel It is being rolled out gradually. As of today, it is not available on all platforms or to all users. Microsoft has made it clear that the goal is to integrate it into subscriptions. Microsoft 365but the pace of deployment is gradual.
Currently, the feature is available in Excel for Windows, Excel on the Web and in Excel for Macprovided your subscription and update channel are compatible. However, there are platforms where, although you can open workbooks containing Python cells, They cannot be recalculated. And you'll see mistakes if you try to do it.
Python in Excel is not available in Excel for iPad, Excel for iPhone or Excel for AndroidOn these devices, workbooks containing Python code in cells can be displayed, but if a recalculation is initiated, the Python cells may return errors. This is because the execution engine is not supported.
Regarding the condition of the product, Python in Excel started as a public preview versionIt is accessible to users of the Microsoft 365 Insider Program through the Beta channel. During this phase, the functionality has been changing and expanding based on community feedback, with the aim of becoming a standard part of the Microsoft 365 offering in the near future.
How to enable and start using Python in Excel
If you have one Microsoft 365 subscription eligible With the correct version of Excel, enabling Python in Excel is fairly straightforward, though not always obvious the first time you try. Ideally, you should start with a blank workbook to familiarize yourself with the workflow before working on critical files.
The first path goes through the ribbon:
- Go to the “Formulas” tab and click the “Insert Python” button.With that gesture you tell Excel that you want to convert the selected cell into a Python cell, in which you can literally write code in the language instead of a traditional formula.
- use the function =PY. Just write =PY In a cell, let it appear in the autocomplete menu and select it with the arrow keys and Tab, or type directly =PY(From that parenthesis onwards, the cell accepts Python code that will be sent to the cloud to perform the calculations.
Once the cell is converted to a Python cell, you will see a “PY” icon within the cell itself, and that same icon is also displayed in the formula bar when the cell is selected. It's a quick way to identify which cells contain Python code versus those that only have Excel formulas.

Combining Python with Excel cells and ranges
One of the keys to this integration is that Python can work directly with the data you already have in the spreadsheet. Without having to export or duplicate them. To do this, Python in Excel uses a custom function called xl(), which acts as a bridge between Excel objects and Python code.
To reference a range from a Python cell, you can enter edit mode in that cell and select the cell or range with the mouse that you want to use. Excel will automatically insert a call into your code to xl() with the corresponding address of the range or table you've selected. In other words, you save yourself from typing it manually.
If you prefer to type the reference directly, you can do that too. For example, to work with the cell A1 From Python, it would be enough to use xl("A1"), whereas for a range like B1: C4 would you write xl("B1:C4")In the case of named tables, the syntax becomes a little more interesting.
Imagine you have a table with headers called MyTableIf you want Python to receive the entire table, including headers, you can use xl("MyTable", headers=True)The specifier indicates that the entire table should be analyzed, and the argument headers=True It ensures that the headers are processed correctly in the DataFrame or structure that is generated.
How to use the formula bar with Python code
When you start writing longer code, the Excel formula bar It becomes your ally. It's not just a line where you can quickly enter a formula, but a small editor that, with Python in Excel, becomes quite important.
You can expand the formula bar By clicking the down arrow to its right. Or by using the keyboard shortcut Ctrl+Shift+UBy doing this, you'll see multiple lines at once, which is very useful when your Python code doesn't fit on a single line and you want to keep it readable.
Within the formula bar you can use the key Intro To create new lines, just as you would in a code editor, instead of accepting the content in the cell. This allows you to write much more structured blocks of code, with line breaks, comments, and slightly more complex logic.
This behavior makes the experience more like working in a lightweight IDEwithout leaving Excel. While you won't have all the options of a professional editor, you will have a sufficiently comfortable environment for analysis scripts, visualizations, and small models.
Python cell output types
Python in Excel is more than just dumping plain numbers into cells. You have considerable control over how the results are returned from your scripts. From the formula bar itself, you can choose the output type, which influences both what you see in the cell and how you can reuse that result within the workbook.
In many cases, you will be interested convert the result into Excel values For example, this happens when the script produces a table that you want to use as a source for pivot tables or classic Excel charts. In that case, the Python cell content is translated into standard cells with native Excel data.
Another option is to return the result as a Python objectWhen you choose this mode, the cell displays a card icon instead of a simple value. Clicking this icon opens a card where you can preview the object. This could be a DataFrame, a list, a Matplotlib figure, etc.
This card is especially useful when you're driving. large or complex objectsIt's simply not practical to fit everything into a single cell. Furthermore, it allows you to retain additional information associated with the object—information that would be lost if you converted it directly to plain Excel data.
Among the most interesting data types that you can return as a Python object are the DataFramesThese objects integrate very well with the analysis workflow, as they allow you to manipulate, filter, and transform data with a level of detail that is sometimes difficult to achieve using only Excel formulas.
Import external data to analyze it with Python in Excel
For Python in Excel to work its magic, the Data must first arrive in the spreadsheet oa Power Query. Unlike a traditional Python script that can read directly from files, APIs, or other sources, here the flow relies on Excel acting as a gateway to the data.
The recommended way to bring information from external sources is to use the feature “Obtain and transform”What is also known as Power QueryFrom there you can connect to CSV files, databases, online services, and much more. And then export the transformed result to a spreadsheet.
Once the data is on the sheet or in a Power Query queryPython can access them through xl() and work with the resulting tables. This way, you combine the initial cleaning and transformation capabilities of Power Query with the advanced processing of Python.
Microsoft documents in detail how Use Power Query to import data for Python into Excel. Precisely because this combination has become one of the pillars of the new way of working with data within Excel, especially in business environments where the sources are diverse.
Python cell calculation order
In a traditional Python script, the Instructions are executed from top to bottomfollowing the order in which you wrote them. In a spreadsheet, however, the calculation engine works by cells and ranges, which requires establishing specific rules for Python cells.
Within the same Python cell, the code is evaluated sequentiallyAs you would expect in any .py file: line 1 executes before line 2, line 2 before line 3, and so on. Each line has an implicit dependency on the previous one. This affects the definition and use of variables within that cell.
But if we look at the sheet as a whole, Excel evaluates the Python cells following a main order by rowsIt iterates through each row from left to right (from column A to XFD) and then moves to the next row. This means that a Python cell located in row 5 will not be calculated before one located in row 4, even if it is further to the left.
This order is very important when you define variables in cells and reuse them in othersBecause you need the cell that declares them to be calculated before the cell that references them. Otherwise, you'll encounter errors or unexpected results, just like with dependencies between Excel formulas.
In practice, this means that it is advisable structure your sheet logically. This way, cells that establish base values or previous calculations are placed before (at the top or further to the left) those that rely on them. This maintains the consistency of the calculation flow.
Recalculation and calculation modes with Python in Excel
Every time you change a value that one or more Python cells depend on, Excel recalculates all Python formulas sequentiallyrespecting the calculation order you just saw. This can be very convenient, but it can also impact performance if your book is large.
To have more control, Excel offers several calculation modes, among them the partial calculation mode and the manual calculation modeThese modes suspend automatic recalculation, both for data tables and Python cells, so that recalculation only occurs when you decide to do so.
If you are in the middle of developing your model, disabling automatic recalculation may significantly improve performance. Especially when your workbook contains many Python scripts or resource-intensive queries. Of course, you'll need to remember to run the calculation again to ensure the results reflect the latest changes.
To change the calculation mode, simply go to the ribbon, open the tab “Formulas” and access “Calculation options”There you can select whether you want automatic, partial, or manual calculation. This applies to both standard formulas and Python cells.
When you are in partial or manual mode you can Force recalculation in three ways:
- Using the key F9.
- Going to Formulas > Calculate now on the tape.
- By clicking on the error symbol that appears next to a cell with an obsolete value (displayed with a strikethrough) and choosing the option “Calculate now” in the drop-down menu.
Python in Excel add-on license and premium capabilities
In addition to the basic functionality integrated into certain Microsoft 365 subscriptions, there is a Python-specific license add-in for Excel which provides access to additional features, primarily geared towards environments where performance and computing power are critical.
This supplemental license includes, among other benefits, premium calculation. This translates to faster execution times for Python formulas. It also results in improved responsiveness in workbooks that combine many Python cells or large volumes of data.
Another important point is that it expands the calculation mode optionsThis provides even finer control over when and how often Python formulas are recalculated. For advanced users and data teams, this can make all the difference when working with complex models.
If you want to know exactly what's included in your subscription and what this add-on includes, Microsoft maintains specific documentation on this. what's included in Microsoft 365 and the additional Python license in Excel. With a detailed breakdown for businesses and education.
Cloud execution, security, and terms of use
All Python calculations in Excel are executed in the Microsoft CloudUsing a standard version of the Python language and a set of libraries provided by Anaconda, this cloud architecture has direct implications for security, performance, and maintenance.
From a security standpoint, Microsoft applies its routine data protection controls and regulatory compliance, including aspects related to the GDPR and the processing of personal data.
If you have a Microsoft 365 Family or Personal subscriptionThe use of this feature is governed by the Microsoft Services AgreementIn business and education settings, however, the following come into play: Product Terms, which specify in a more granular way what is allowed and under what conditions.
One key detail is that You don't need to have Python installed on your computer. to leverage Python in Excel. And, even if you have a highly customized local installation, these configurations don't carry over to the cloud computing environment, which uses its own standard, isolated distribution.
Copilot in Excel with Python: AI at the service of analysis
The integration of Python into Excel doesn't come alone: it's complemented by Copilot in ExcelMicrosoft's AI assistant, which is now also capable of working with Python code, is designed specifically for users who, without being programming experts, want to take their analyses a step further.
With Copilot you can formulate requests in natural language and let the system handle generating the necessary Python code, performing the calculations, and displaying the result in the spreadsheet.
This approach helps to lower the barrier to entry This applies to both Python and advanced Excel functions, because it transforms tasks that previously required considerable technical knowledge into something much more conversational and guided.
For users who are already proficient in Python, Copilot can also serve as support for test analysis variantsExplore patterns or quickly build model prototypes without spending so much time manually writing code.
Why using Python in Excel improves your daily life
The arrival of Python in Excel represents a significant leap forward for anyone working with data. The ability to manipulate and explore data Using pandas, creating graphs with Matplotlib or Seaborn, or building statistical models with Statsmodels directly in the sheet changes the landscape considerably.
With this integration you can Take advantage of all those libraries without installing anything extra. on the team, integrating the results of your scripts with classic Excel formulas, pivot tables, slicers, and native charts. All in the same environment your colleagues already know.
The ability to create automations directly in the workbook. From regular data cleaning to report generation, including building dashboards by combining interactive Excel charts with visualizations produced by Python.
Data security, which has always been a concern in business environments, remains under the umbrella of Microsoft 365This makes it easy to share books, scripts, and results through Teams, Outlook, or SharePoint without having to leave the corporate ecosystem.
Automating Excel: Code vs. AI-powered tools
Alongside Microsoft's native approach, another way of working has been gaining traction. AI-powered automation tools These solutions allow you to manipulate spreadsheets using natural language. They fall somewhere between classic Python scripts and assistants like Copilot.
The most traditional approach remains the programmatic pathUsing libraries like openpyxl to automate reading, writing, formatting, and creating charts. This method is ideal for developers who want to integrate Excel into complex data pipelines. Or in larger applications, controlling every detail of the cells and the workflow.
On the other hand, AI tools like "Excel agent" are becoming increasingly popular (such as Excelmatic in some examples), where you simply upload a file, Describe what you want in simple language (clean data, create a chart, add formulas) and you receive the modified workbook.
This “no-code” approach is very attractive to teams of marketing, sales or operations. In general, this is for those who need to quickly automate reports and analyses without investing time in learning libraries or debugging scripts. AI takes care of translating business instructions into concrete technical operations.
The interesting thing is that you can now choose between three main paths to automate Excel:
- Code with classic libraries.
- Native Python integration within Excel.
- External AI agents.
The best option depends on the technical level of the team, the volume of data, and how much fine control you need over the process.
Given this scenario, the combination of Python and Excel is becoming established as a very powerful solution For both technical profiles and business users. From Microsoft's native cloud integration with Copilot, through classic libraries like openpyxl or pandas, to new AI-powered tools that automate tasks for you. You have at your disposal a huge range of options to take your spreadsheets to the next level without sacrificing the comfort of the environment you use every day.


