From the course: Hands-On Advanced Python: Data Engineering Basics

Unlock this course with a free trial

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

Using the reduce function

Using the reduce function

- [Instructor] Sometimes when you're working with a large dataset you want to be able to reduce that dataset down to a single value. And we've already seen some use cases for that right here in this course. So for example, the min and max functions, essentially, just reduce the entire dataset down to a single minimum or maximum value. So for example, we used min and max to find the coldest and warmest days out of the entire dataset. Python provides a more generic function called "Reduce" that does the same thing using a callback function that your code provides in order to control the reduction algorithm. So let's start with a simple example to see how this works. Let's go ahead and open up the reduce func example. And what I'm going to do first, is import the reduce function and that's in the func tools module. So I'm going to write from functools, import reduce. So let's use this reduce function to calculate how…

Contents