Pandas DataFrame: filter() function
DataFrame - filter() function
The filter() function is used to subset rows or columns of dataframe according to labels in the specified index.
Note that this routine does not filter a dataframe on its contents. The filter is applied to the labels of the index.
Syntax:
DataFrame.filter(self, items=None, like=None, regex=None, axis=None)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
items | Keep labels from axis which are in items. |
list-like | Required |
like | Keep labels from axis for which “like in label == True”. | string | Required |
regex | Keep labels from axis for which re.search(regex, label) == True. | string (regular expression) | Required |
axis | The axis to filter on. By default this is the info axis, ‘index’ for Series, ‘columns’ for DataFrame. | int or string axis name | Required |
Returns: same type as input object
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - equals() function
Next: DataFrame - first() function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework