From the course: Advanced Python: Working With Data

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Data filtering

Data filtering

- [Instructor] Sometimes when you're working with a large dataset, you want to be able to focus on a subset of the overall data. In other words, you want to be able to filter out the data that's not interesting and keep the data that is. So in this example, we're going to see how to use the filter function to achieve this. We're here in Ch_1, let's open up filtering.py. And here in my example code, I have a couple of functions, along with some predefined sequences of data, okay? I've got a couple of sequences, this one's numbers, and this one is random letters, and I'm going to use the filter function to refine each of these datasets. The filter function works by specifying two arguments. The first is a function that returns true or false, depending on whether a particular data item should be retained or dropped, and then the second argument is the dataset to operate on, right? So the filter function calls that second…

Contents