The Pandas function
dataframe.filter() is used to subset the rows or columns of data according to the labels in the specified index. Note that this procedure does not filter the data frame by its content. The filter is applied to index labels.
Syntax: DataFrame.filter (items = None, like = None, regex = None, axis = None)
items: List of info axis to restrict to (must not all be present)
like: Keep info axis where “arg in col == True”
regex: Keep info axis with re.search (regex, col) == True
axis: The axis to filter on. By default this is the info axis, ’index’ for Series, ’columns’ for DataFrame
Returns: same type as input object
Items, like and regex parameters are mutually exclusive. the default axis is the information axis used when indexing with .
To link to the CSV file, click here
Example # 1: Use the
filter () function to filter out any three frame columns data.
Now filter out the Name, College and Salary columns.
Example # 2: Use the
filter () function to substitute all columns in a data frame whose name contains the letter "a" or "A". p>
filter () function also accepts a regular expression as one of its parameters.
The regular expression" [aA] "searches for all column names that have" a "or" A "in their name.