Pandas DataFrame ge() method with examples

Spread the love

The ge() method compare each value in a DataFrame to check if it is greater than or equal to a specified value, or a value from a specified DataFrame objects, and returns a DataFrame with boolean True/False for each comparison.

Syntax –

DataFrame.ge(other, axis='columns', level=None)

other – Any single or multiple element data structure, or list-like object.

axis – Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’).

level – Broadcast across a level, matching Index values on the passed MultiIndex level.

Examples –

Let’s create a DataFrame to work with.

import pandas as pd

data = {'Apple':[89, 89, 90, 110, 125, 84, 131, 123, 123, 140, 145, 145],
       'Orange': [46, 46, 50, 65, 63, 48, 110, 120, 60, 42, 47, 62],
       'Banana': [26, 30, 30, 25, 38, 22, 22, 36, 20, 27, 23, 34 ],
       'Mango': [80, 80, 90, 125, 130, 150, 140, 140, 135, 135, 80, 90]}

index = ['Jan','Feb','Mar','Apr','May','June','Jul','Aug','Sep','Oct','Nov','Dec']
df = pd.DataFrame(data, index=index)
df

1 . Compare a DataFrame with a single value using the DataFrame.ge() method –

Let’s say you want to know if the values of a dataframe is greater than or equal to 100. For this you can use the ge() method.

df.ge(100)

2 . Comparing a series with another series using the DataFrame.ge() method –

You can also compare a series with another series using the ge() method.

df['Apple'].ge(df['Mango'])

Rating: 1 out of 5.

Leave a Reply