Data wrangling

Filter rows in Pandas DataFrame

Filter rows in Pandas DataFrame based on condition. You can select a column and apply condition on it. Please be aware that there are different conditions for numeric and categorical columns.

rowspandasfilter

Interactive recipe

You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.

In the below recipe, we assume that you have following variables available in your notebook:

  • df_1 (type DataFrame)
  • df_2 (type DataFrame)

Python code

# Python code will be here

Code explanation

  1. Select a column and apply a filtering condition to its values. Only rows that fulfill the condition will be present in the DataFrame.
  2. Display new DataFrame shape.

If you would like to filter based on more columns, please just apply Filter rows in the next cell on the next column.