Python | Pandas dataframe.filter() Last Updated : 19 Nov, 2018 Comments Improve Suggest changes Like Article Like Report 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. Pandas 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) Parameters: 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. Python3 # importing pandas as pd import pandas as pd # Creating the dataframe df = pd.read_csv("nba.csv") # Print the dataframe df Now filter the "Name", "College" and "Salary" columns. Python3 1== # applying filter function df.filter(["Name", "College", "Salary"]) Output : Example #2: Use filter() function to subset all columns in a dataframe which has the letter 'a' or 'A' in its name. Note : filter() function also takes a regular expression as one of its parameter. Python3 # importing pandas as pd import pandas as pd # Creating the dataframe df = pd.read_csv("nba.csv") # Using regular expression to extract all # columns which has letter 'a' or 'A' in its name. df.filter(regex ='[aA]') Output : The regular expression '[aA]' looks for all column names which has an 'a' or an 'A' in its name. Comment More infoAdvertise with us Next Article Python | Pandas dataframe.filter() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-dataFrame Pandas-DataFrame-Methods +1 More Practice Tags : python Similar Reads Python | Pandas dataframe.eq() 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. Pandas dataframe.eq() is a wrapper used for the flexible comparison. It provides a con 3 min read Python | Pandas DataFrame.isin() In this article, we will explore the Pandas DataFrame.isin() method provided by the Pandas library in Python. Python is widely recognized for its proficiency in data analysis, largely attributed to its exceptional ecosystem of data-centric packages. Among these, Pandas stands out as an essential too 2 min read Python | Pandas dataframe.clip_lower() 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. Pandas dataframe.clip_lower() is used to trim values at specified input threshold. We 2 min read Python | Pandas dataframe.mask() 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. Pandas dataframe.mask() function return an object of same shape as self and whose corr 3 min read Filter Pandas DataFrame by Time In this article let's see how to filter pandas data frame by date. So we can filter python pandas data frame by date using the logical operator and loc() method. In the below examples we have a data frame that contains two columns the first column is Name and another one is DOB. Example 1: filter da 1 min read Like