From the course: Python in Excel: Working with pandas DataFrames
Unlock the full course today
Join today to access over 23,300 courses taught by industry experts.
Row filtering
From the course: Python in Excel: Working with pandas DataFrames
Row filtering
- [Instructor] When using an Excel table, the most common operations are filtering and sorting rows. Let's see how this is done with data frames. As usual, in the first cell, K1, we turn our Excel data into a data frame. Now in cell K2, I would like to filter the rows to those students who have completed the course. Previously, we have already used the lock attribute with column names, but lock also accepts a series or list of Booleans. Wherever the Boolean is true, the row or column will be included. So in this statement, we use the complete column to only show those students who have completed the course. As you can see by looking at the preview, this filters the result to only those students who finished the course. But what if we want to show only students from Italy? In this case, we first need to create a Boolean series where true means Italy and falls means every other country. The next cell, K3, shows you that we can accomplish this by comparing the country column with the…
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.