From the course: Faster pandas

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using Numba

Using Numba

From the course: Faster pandas

Start my 1-month free trial

Using Numba

- [Instructor] Let's see how much Numba can speed up our code. So, ipython, and we're going to import pandas as pd. And we're going to import numpy as np. And we're going to create a series. So pd dot series, and we're going to use np dot random dot randint, between minus three and 200, and we're going to take 1 million elements. And now it's the final function. So relu of n, if n is smaller than zero return zero, otherwise return n. And we can time it, so time it s dot apply, and it's 549 milliseconds. Now let's use Numba. So import Numba, and we're going to use the Numba dot vectorize decorator. And we're going to say def vect relu of n. And again, if n is smaller than zero, return zero, otherwise return n. And when we run the function on the number, we will get a number. When we run the function on a series, so pd dot series of let's say minus one, two and three, we will get the function applied to each element of the series. Let's see if they are the same, so np all close s dot…

Contents