228k views
3 votes
How to filter a dataframe based on a column value

1 Answer

0 votes

Final answer:

To filter a dataframe based on a column value, use boolean indexing in Python by specifying a condition based on the desired filter. This creates a new dataframe that contains only the rows meeting the filter criteria.

Step-by-step explanation:

To filter a dataframe based on a column value, you can use the boolean indexing technique in Python. First, you need to specify the condition based on which you want to filter. For example, if you have a dataframe called 'df' and want to filter rows where the column 'age' is greater than 25, you can use the code:

filtered_df = df[df['age'] > 25]

This will create a new dataframe called 'filtered_df' that only contains the rows where the 'age' column has values greater than 25.

User Ilya Bibik
by
7.9k points