FormulaCamp
Completed
15. Python in Excel and AI · Introduction · 15 min

1. Python in Excel and Copilot

Lesson 1 of 6
    Lesson theory

    Python in Excel is the =PY() function, which runs Python code right in a cell. The code is calculated in the Microsoft cloud, so it needs a Microsoft 365 subscription and an internet connection. Check Microsoft's documentation for the current list of supported platforms and plans.

    df = xl("A1:C500", headers=True)      # range -> pandas DataFrame
    df.groupby("City")["Amount"].sum()     # totals by city

    Popular libraries are available, including pandas, NumPy, Matplotlib and seaborn. You can return the result as an Excel value or as a Python object (a DataFrame or a chart).

    Copilot in Excel helps you write formulas, explains them, and builds PivotTables and charts from a plain-language request. Analyze Data is another built-in way to explore a table. But check what AI gives you: recalculate a few values by hand, read the formula, and don't send confidential data anywhere your company's policy forbids.

    Test yourself

    1. Where does Python in Excel code run?
    2. What does xl("A1:C500", headers=True) return?
    3. What is the right way to work with a Copilot answer?