Ge() Function Of Pandas DataFrame Class

Overview:

  • The instance method DataFrame.ge() of Python pandas library, implements the relational binary operation “Greater than or equal to”(>=).
  • When two instances of pandas.DataFrame classes are compared using the ge() method, the results are returned as another DataFrame consisting of the results as Boolean values.
  • An element in the resultant DataFrame is True, if the element from the first DataFrame is greater than or equal to the element from the second DataFrame. It is False otherwise.

 

Example:

import pandas as pd

 

# Lists of tuples with integers

dataCollection1 = [(0, 0, 0),

                   (1, 1, 1),

                   (2, 2, 2)];

 

dataCollection2 = [(0, 1, -1),

                   (-1, 1, 0),

                   (1, 2, 3)];

 

# Create dataframes from lists of tuples

dataFrame1 = pd.DataFrame(data=dataCollection1);

dataFrame2 = pd.DataFrame(data=dataCollection2);

 

# Compare two data frames using ge()

comparisionResult = dataFrame1.ge(dataFrame2);

 

print("Contents of the First DataFrame:");

print(dataFrame1);

 

print("Contents of the Second DataFrame:");

print(dataFrame2);

 

print("DataFrame One ge(<) DataFrame Two:");

print(comparisionResult);

 

Output: 

Contents of the First DataFrame:

   0  1  2

0  0  0  0

1  1  1  1

2  2  2  2

Contents of the Second DataFrame:

   0  1  2

0  0  1 -1

1 -1  1  0

2  1  2  3

DataFrame One ge(<) DataFrame Two:

      0      1      2

0  True  False   True

1  True   True   True

2  True   True  False


Copyright 2024 © pythontic.com