Python in Excel: A New Way to Perform Data Analysis and Visualization
Python in Excel: A New Way to Perform Data Analysis and Visualization. In August 2023, Microsoft introduced a public preview of Python integration within Excel. This enhancement enables users to execute Python code directly within Excel cells, opening up opportunities for a wide range of tasks, including data analysis, visualization, and machine learning.

Python in Excel: A New Way to Perform Data Analysis and Visualization
To begin utilizing Python in Excel, the initial step is to install the Python add-in. This can be accomplished by navigating to the “File” tab, then selecting “Options.” Afterward, proceed to the “Add-ins” tab and click on the “Manage” button adjacent to “COM Add-ins.” In the list of add-ins, choose the “Microsoft Python for Excel” add-in and click on the “Go” button.
Once the Python add-in is successfully installed, you can commence utilizing Python code within Excel cells. To achieve this, enter the following formula into a cell:
=PY("python code")
Replace “python code” with the specific Python code you intend to execute. For example, the following code snippet will display the current date and time within the cell:
=PY("print(datetime.datetime.now())")
Additionally, you have the capability to import Python libraries into Excel using the import
statement. For instance, the following code example imports the pandas
library:
import pandas as pd
After importing a Python library, you can leverage it for tasks such as data analysis and visualization. As an illustration, the following code reads a CSV file into a Pandas DataFrame:
df = pd.read_csv("data.csv")
It’s important to note that the Python in Excel feature is currently in a preview stage, which comes with some limitations. For instance, Python code can only be used within Excel cells formatted as text. Nevertheless, Microsoft is actively working on enhancing and expanding the capabilities of this feature in future updates.
You have the capability to achieve the following with Python in Excel:
- Run Python code directly in the Excel formula bar: no Python installation is required
- Simplify data wrangling: Leverage powerful Python libraries such as pandas to transform complex data sets into actionable insights—all without leaving your Excel workbook
- Create advanced visualizations: Utilize Python visualization libraries like Matplotlib and Seaborn to create rich and extensive visualizations directly in your Excel workbook
- Perform deep statistical analysis: accomplish comprehensive statistical tasks with libraries like scikit-learn and stats models, right in Excel
- Share your work: Collaborate with your Excel-using colleagues just by sharing your Excel workbook.
All You Need Is =PY()
Using Python in Excel is as simple as typing “=PY(” in your Excel cell, followed by your Python code. The results of your Python calculations or visualizations will then appear in your Excel worksheet.

In summary, the recent addition of Python integration in Excel marks a significant advancement, simplifying complex data analysis and visualization tasks for users. If you are familiar with Python, I encourage you to explore and experiment with this new feature.