In this subsection, we will learnhow to filter column-wise data. We can filter columns using the filter() method. The slicing []. filter() method selects the columns when they're passed as a list of columns. Take a look at the following example:
# Filter columns
data.filter(['name', 'department'])
This results in the following output:
Similarly, we can also filter columns using slicing. In slicing, a single column does not need a list, but when we are filtering multiple columns, then they should be on the list. The output of a single column is a pandas Series. If we want the output as a DataFrame, then we need to put the name of the single column into a list. Take a look at the following example:
# Filter column "name"
data['name']
0 Allen Smith
1 S Kumar
2 Jack Morgan
3 Ying Chin
4 Dheeraj Patel
5 Satyam Sharma
6 James Authur
7 Josh Wills
8 Leo Duck
Name...