From the course: Data Analysis with Python and Pandas

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

The where() function

The where() function

- [Instructor] So let's take a look at the NumPy where function. The where function performs a logical test and returns a specified value if the test returns True, or another value if the test returns False. So here's the general syntax. We just specify NumPy dot where, and then our first argument is going to be the logical test or combination of tests. We'll then specify a value to return if that test returns True, and then we'll specify a value to return if the test returns False. So we just need to specify NumPy. We'll then pass in a logical expression that evaluates to True or false, a value to return when the expression is True, and a value to return if the expression is False. So let's go ahead and take a look at an example. Here I have an inventory array and a product array. I'm going to call the NumPy where function. And if inventory array is less than or equal to 0, it'll return out of stock or in stock. So let's take a look at what was returned. The first three values in…

Contents