From the course: Python Functions for Data Science
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Python filter() function - Python Tutorial
From the course: Python Functions for Data Science
Python filter() function
- [Instructor] Filter is another built in Python function that can be very helpful when working with data. Filter takes in a function and a sequence as inputs in that order and returns an iterator constructed from the items of the given sequence, for which the given function returns true. To collect everything that lies in the result all at once, you can call list on the iterator that filter yields. Note that a list is a built in Python feature that allows you to create a sequence. To illustrate how filter can be used, I'll be walking you through an example. Let's say I have a data set that contains students' grades across five exams. I defined a function named mean at least 70, that takes in a student ID as input, computes the mean exam grade for the student with a given student ID and returns true if that value is at least 70 and false otherwise. Also I collected all the distinct student IDs from the dataset as a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.