From the course: Data Analysis with Python and Pandas

Unlock this course with a free trial

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

Solution: apply() and where()

Solution: apply() and where()

- [Instructor] All right, so our solution code is up on the right. Let's go ahead and dive into the notebook. All right, so we have our oil seers here, and we want to define a function. Let's call this buy bool. Even though it's not outputting a true Boolean value, it's a semi Boolean, right? We're you're either outputting wait or buy. And this is going to take in a price and a limit. And so if our price is less than our limit, we're going to return buy. Otherwise, we'll return wait. And so we have our function defined. Now we can go ahead apply this to our series. So oil series dot apply buy bool. And now we need to specify our args. So args equal. And then we need to specify our oil series dot quantile. So oil series dot quantile. we want to pass in .9 for the 90th percentile. And there we go. So if our price is less than our limit, we have a series that says buy. Otherwise, we have a series that says wait. And just to check what our quantile is here, let's go ahead and return this.…

Contents