Remove rows in less than a certain value

Given a pandas dataframe, we have to remove rows in less than a certain value.
Submitted by Pranit Sharma, on November 09, 2022

Pandas is a special tool that allows us to perform complex manipulations of data effectively and efficiently. Inside pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and data.

Removing rows in less than a certain value

Suppose we are given a DataFrame with multiple columns of integer values and we need to filter out the data of this DataFrame which is less than a certain value.

Assuming that certain values are constant throughout this operation, we will use the simple filtering process of selecting some values from DataFrame along with a condition related to the fixed value.

We will use the tilde sign operator for this purpose, tilde sign (~) in pandas is used when we work with Boolean values. In programming, we sometimes use some specific values that only have two values, either True or False. These values are known as Boolean values.

Let us understand with the help of an example,

Python code to remove rows in less than a certain value

# Importing pandas package
import pandas as pd

# Importing numpy package
import numpy as np

# Creating a dictionary
d = {
    'A': [1,2,5,6,9,10],
    'B': [3,4,7,8,11,12]

# Creating a DataFrame
df = pd.DataFrame(d)

# Display dataframe
print('Original DataFrame:\n',df,'\n')

# Filtering DataFrame
res = df[~(df['B'] <= 10)]

# Display result


Example: Remove rows in less than a certain value

Python Pandas Programs »


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.