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.

Understanding ufuncs

Understanding ufuncs

From the course: Faster pandas

Start my 1-month free trial

Understanding ufuncs

- (Tutor) ufunc is a short for universal functions. These are functions provided by pandas and NumPy. These functions work both on arrays and on scalars ,regular numbers. The pandas NumPy provided ufuncs, are highly optimized and faster than some function provided by Python. And for sure faster than the ones you'll write yourself. let's look at an example. So I Python ,and we import pandas as pd. And then let's create pd . series of range of 10,000 elements. And it's time the built-in Python max on the Series. So timeit max of s. And this is two milliseconds. And now let's time the max method of the series. So timeit s.max. This is 104 microseconds. So, 2000 microseconds divided by 104 And we've got about 20 times faster by switching to the pandas provided functions. The built in Python functions handle more types and walk on a wider range of data types. But you pay performance price for this versatility.

Contents