PY function: How to use Python in Excel

Eray Eliaçik
Aug 26, 2023
Updated • Aug 24, 2023

You may ask, "How to use Python in Excel?" after Microsoft has introduced a game-changer for Excel enthusiasts: the =PY function. Here is the answer.

This revolutionary tool seamlessly integrates Python's analytical prowess into Excel's familiar grid, offering a dynamic and secure way to enhance your data manipulation game. This guide delves into the exciting world of the =PY function, understanding its capabilities, exploring its secure framework, mastering its application, and how to use Python in Excel well.

Whether you're a seasoned Pythonista or just starting your coding journey, the =PY function welcomes you with open arms.

Python in Excel: Introducing PY Function

At its core, the =PY function is a bridge between Excel's familiar environment and Python's robust analytical capabilities. Microsoft's brainchild, this function empowers users to effortlessly incorporate Python code into Excel, amplifying data analysis, manipulation, and visualization.

(Image credit)

Security and privacy are paramount in today's digital landscape, and Microsoft is acutely aware of this. The =PY function operates within the secure confines of the Microsoft Cloud, aligning itself with the rigorous compliance standards of Microsoft 365. Your data's sanctity remains intact; Python code cannot access your user identity. A unique security layer shields workbooks from the internet, isolating them in distinct containers. Microsoft has stitched a fortress around your data, ensuring a worry-free analytical experience.

PY function: How to use Python in Excel

Using the =PY function is a breeze. Picture this: You are in an Excel cell and ready to tap into Python's magic. Simply type "=PY" followed by the Python code relevant to your task. The possibilities are limitless - from complex calculations to data wrangling and eye-catching visualizations. Imagine merging intricate datasets seamlessly, all from within Excel, courtesy of the =PY function.

(Image credit)

Let's break it down with an example. Say you have two data sets with tangled information. With the =PY function, you can swiftly script Python code to untangle and merge them. Voilà! Your Excel sheet is now a canvas of organized insights, all thanks to the power of Python.

For detailed information, click here.

The path forward

Microsoft has exciting plans for the =PY function. This functionality is available to Microsoft 365 subscribers during the initial preview stage. But remember, the journey doesn't end there. Microsoft encourages users to explore, experiment, and provide feedback during this phase.

After the preview, some functionalities might require a paid license, underlining the continuous value this function offers.

To join the Microsoft 365 Insider Program, all you have to do is:

  1. Go to the Microsoft Insider Program website
  2. Sign in to your Microsoft account
  3. Browse through the available Insider Programs
  4. Opt for the "Beta Channel" as it provides access to Python in Excel


The =PY function isn't just a function; it's a doorway to a dynamic synergy between Excel and Python. It's about crafting elegant solutions to intricate problems and unraveling your data's potential with finesse.

So, whether you're a data aficionado or a coding enthusiast, embrace the =PY function and elevate your Excel experience to new heights. Secure, versatile, and transformative - the =PY function is your backstage pass to the future of data-driven excellence.

Featured image credit: Microsoft


Previous Post: «
Next Post: «


  1. abzee said on August 31, 2023 at 4:57 am

    very interesting article, ignore the toxic comments, keep up the good work.

  2. marc said on August 31, 2023 at 1:51 am

    who cares? write more interesting articles

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.