Now, let's filter row-wise data. We can filter data using indices, slices, and conditions. In indices, you have to pass the index of the record, while for slicing, we need to pass the slicing range. Take a look at the following example:
# Select rows for the specific index
data.filter([0,1,2],axis=0)
This results in the following output:
In the preceding example, we have filtered the data based on indexes.
The following is an example of filtering data by slicing:
# Filter data using slicing
data[2:5]
This results in the following output:
In condition-based filtration, we have to pass some conditions in square brackets, [ ], or brackets, ( ). For a single value, we use the == (double equal to) condition, while for multiple values, we use the isin() function and pass the list of values. Let's take a look at the following example:
# Filter data for specific value
data[data.department=='Sales']
This results in the following output...