Microsoft Excel Tutorial: Using a function in Python for Excel to count how many times a word occurs in a cell in Excel.
To download this workbook: www.mrexcel.com/youtube/6Ydb6...
Welcome to another episode of the MrExcel podcast, where we dive into all things Excel. In today's episode, we will be discussing a couple of different titles, including "How many times does this word occur in that long transcript?" and "Excel Labs can already do this better than Python." Our question for today comes from Fred, who wants to know how to count the number of times a word appears in a long transcript of Seinfeld scripts. Can we do this in Excel? Let's find out.
In this video, Bill Jelen, also known as MrExcel, walks us through the process of counting the occurrences of a specific word in a phrase using Excel. He breaks it down into five simple steps and shows us how to apply this formula to a long transcript of over 12,000 characters. But then, he poses the question, can we do this more efficiently using Python? He demonstrates how to use the Python function "count" to achieve the same result in just one line of code. This leads to the idea of creating a custom Python function for this task.
Bill then takes us through the process of creating a custom Python function that can be used in Excel. He explains the code and shows us how to call the function and specify the parameters. He also shares some tips and tricks he learned along the way, such as using two sets of brackets to create a data frame instead of a series. He also shows us how to use the Excel Labs add-in to create a lambda function that can be used in place of the custom Python function.
But why go through all this trouble when we can just use the formulas in Excel? Bill addresses this question and explains the benefits of using Python for certain tasks. He also shares some outtakes that demonstrate why using tables in Excel can cause issues with these formulas. So, if you're looking to improve your Excel skills and learn how to use Python in Excel, this video is a must-watch. Don't forget to like, subscribe, and ring the bell for more Excel tips and tricks. And as always, feel free to leave any questions or comments down below. Thanks for watching!
Buy Bill Jelen's latest Excel book: www.mrexcel.com/products/latest/
You can help my channel by clicking Like or commenting below: www.mrexcel.com/like-mrexcel-...
The first solution is a series of six formulas in Excel, including SUBSTITUTE, LEN, and more. While it is complicated in Excel, there is a much easier way in Python, using the .Count function. So, Python has a simpler version but how do you call the function from Excel?
After the Python solution, I used the Excel Labs add-in to convert the original six formulas to a LAMBDA.
Other topics here:
Saving Python function in a cell
Adding Text as line of a Python script to appear in the cell.
Printing to the Python Console
Removing the Index column using two sets of square brackets
In the Out take, the Python Function can not be part of a table.
Table of Contents
(0:00) Python functions in Excel
(0:17) Problem Statement Count ThisWord in Phrase
(0:54) SUBSTITUTE function in Excel
(1:16) LEN function in Excel
(2:29) Python count function
(2:54) Storing Python function in A1
(3:29) Adding Text to Python to appear in cell
(4:15) Calling the Python function using Excel data
(4:45) Call per row or whole frame
(5:10) Printing to Python Console in Excel
(5:35) Does not work next to Ctrl+T tables
(5:56) Removing Index returned by Python in Excel
(6:52) Returning one column? Use double square brackets to prevent Index
(7:39) Writing a LAMBDA using Excel Labs add-in
(8:11) Add Function from Grid
(8:48) Testing the LAMBDA version
(9:33) Clicking Like really helps the algorithm
(10:06) Outtake Does not work with Tables
#excel #microsoft #microsoftexcel #exceltutorial #exceltips #exceltricks #excelmvp #freeclass #freecourse #freeclasses #excelclasses #microsoftmvp #walkthrough #evergreen #spreadsheetskills #analytics #analysis #dataanalysis #dataanalytics #mrexcel #spreadsheets #spreadsheet #excelhelp #accounting #tutorial #python
This video answers these common search terms:
using python in excel
python code to count how many times a word appears in a cell
printing to python console in excel
removing index column from python data frame in excel
python in excel will not work with a table
how to use advanced formula environment in excel to combine subformulas
Join the MrExcel Message Board discussion about this video at www.mrexcel.com/board/threads...
14 июл 2024