Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
dataframe.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(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
The items, like, and regex parameters are enforced to be mutually exclusive. axis defaults to the info axis that is used when indexing with .
For the link to CSV file click here
Example #1: Use
filter() function to filter out any three columns of the dataframe.
Now filter the “Name”, “College” and “Salary” columns.
Example #2: Use
filter() function to subset all columns in a dataframe which has the letter ‘a’ or ‘A’ in its name.
filter() function also takes a regular expression as one of its parameter.
The regular expression ‘[aA]’ looks for all column names which has an ‘a’ or an ‘A’ in its name.
- Python | pandas.to_markdown() in Pandas
- Python | pandas.map()
- Python | Pandas Series.var
- Python | Pandas Series.pow()
- Python | Pandas Series.dt.tz
- Python | Pandas Series.mul()
- Python | Pandas dataframe.mod()
- Python | Pandas Series.div()
- Python | Pandas dataframe.mul()
- Python | Pandas Series.xs
- Python | Pandas Series.get()
- Python | Pandas Series.abs()
- Python | Pandas dataframe.ne()
- Python | Pandas dataframe.sub()
- Python | Pandas Series.where
- Python | Pandas Series.sum()
- Python | Pandas Timestamp.day
- Python | Pandas Series.str.contains()
- Python | Pandas.melt()
- Python | Pandas Series.last()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.