Python in Excel 365 Tutorial: Master Data Analysis Fast

Logan Jul 13, 2026

Python, a powerful and versatile programming language, can significantly streamline your work with Excel, especially with the recent updates in Excel 365. If you're ready to elevate your data management skills, mastering Python in Excel 365 is a vital step. This tutorial will guide you through the process, from installing the necessary packages to automating complex tasks.

the text python excel tutor the defensive guide article
the text python excel tutor the defensive guide article

Before diving in, ensure you have Office 365, Python 3.7 or later, and an Integrated Development Environment (IDE) like Jupyter Notebook or PyCharm installed. We'll use the `openpyxl` library, so install it using pip: `pip install openpyxl`.

Python in Excel - Beginner Tutorial
Python in Excel - Beginner Tutorial

Reading and Writing Excel Files

Python's `openpyxl` library enables you to read, write, and modify Excel files easily. It supports XLSX files, which is what Excel 365 uses.

a woman standing in front of a poster with the words python in excel on it
a woman standing in front of a poster with the words python in excel on it

First, let's load an Excel file and access its data:

Loading Excel Files

someone typing on a laptop with the words automate excel with python
someone typing on a laptop with the words automate excel with python

Use the following code to load an Excel file using `openpyxl`.

from openpyxl import load_workbook

wb = load_workbook(filename='example.xlsx')

Accessing Data

Ezekiel (@ezekiel_aleke) on X
Ezekiel (@ezekiel_aleke) on X

Access data from sheets in the loaded workbook:

ws = wb['Sheet1']  # Access 'Sheet1'

# Print all values in the first column
for i in range(1, ws.max_row + 1):
    print(ws.cell(row=i, column=1).value)

Manipulating Data in Python

How to Automate an Excel Sheet in Python? - GeeksforGeeks
How to Automate an Excel Sheet in Python? - GeeksforGeeks

Once you've accessed the data, Python's powerful data manipulation capabilities come into play. Let's explore filtering and sorting data.

Filtering Data

Python in Excel
Python in Excel
All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)
How to read Multiple Columns from CSV File in Python? With Source Code
How to read Multiple Columns from CSV File in Python? With Source Code
Python Cheatsheet
Python Cheatsheet
Python Cheat Sheet for Beginners
Python Cheat Sheet for Beginners
the diagram shows how to use python commands for web pages and other contents, including data
the diagram shows how to use python commands for web pages and other contents, including data
Python tkinter Toolbox
Python tkinter Toolbox
Ultimate Python Cheat Sheet for Beginner
Ultimate Python Cheat Sheet for Beginner
5 Ways to Read Excel Data using Python | Every Programmer Must Know | Python - Excel Hacks
5 Ways to Read Excel Data using Python | Every Programmer Must Know | Python - Excel Hacks
Python Tutorial
Python Tutorial
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
Can Excel Use Python?
Can Excel Use Python?
MLTut
MLTut
Python Unit 5 Cheat Sheet 🐍 | File Handling & OOP Basics (AKTU)
Python Unit 5 Cheat Sheet 🐍 | File Handling & OOP Basics (AKTU)
Python list exercises guide
Python list exercises guide
Python Programming, Python
Python Programming, Python
30 Python Projects For Beginners and Advanced Learners (2023)
30 Python Projects For Beginners and Advanced Learners (2023)
SQL to Python to Excel Cheat Sheet for Data Analysis
SQL to Python to Excel Cheat Sheet for Data Analysis
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
a computer screen with the words python string method
a computer screen with the words python string method

Extract specific data based on certain conditions using list comprehensions and Python's built-in functions.

# Suppose we have a column of data in 'A1:A100'
data = [cell.value for cell in ws['A1':'A100'] if cell.value is not None]

# Filter data based on a condition
filtered_data = [x for x in data if x > 50]

Sorting Data

Python's `sorted()` function sorts data based on a specific column. To sort data in-place, use the `sort()` method of a list.

# Sort data in ascending order
sorted_data = sorted(data)

# Sort data in-place
data.sort()

Now that you've mastered basic data manipulation, let's explore automating tasks in Excel 365.

Embrace the power of Python and Excel 365 combined. Automate repetitive tasks, filter, and sort data easily, reducing manual work and increasing accuracy. Happy coding!