A practical guide for efficient data analysis

Pandas is a popular data analysis and manipulation library for Python. The core data structure of Pandas is dataframe which stores data in tabular form with labelled rows and columns.

A common operation in data analysis is to filter values based on a condition or multiple conditions. Pandas provides a variety of ways to filter data points (i.e. rows). In this article, we will cover 8 different ways to filter a dataframe.

We start by importing the libraries.

import numpy as np
import pandas as pd

Let’s create a sample dataframe for the examples.

df = pd.DataFrame({

name':['Jane','John','Ashley','Mike','Emily','Jack','Catlin'],
'ctg':['A','A','C','B','B','C','B'],
'val':np.random.random(7).round(2),
'val2':np.random.randint(1,10, size=7)
})

#python #programming #data-science #ways to filter pandas dataframes #filter pandas dataframes #pandas dataframes

8 Ways to Filter Pandas Dataframes
1.40 GEEK