gt() Function Of Pandas DataFrame Class

The gt() function does element-wise comparison of two DataFrame instances and returns the resultant DataFrame.It implements the binary relational operation 'greater than'.The resultant DataFrame is comprised of Boolean values.The python example applies gt() between two dataframe instances and prints the result.

Dataframe Binaryoperatorfunctions Updated 22 Jul 2019 1 min read

Overview

  • The gt() method of DataFrame class, compares elements of a pandas DataFrame instance with another DataFrame instance. If the element from the first DataFrame is greater than the element from the second DataFrame, gt() returns True**in the resultant DataFrame. Returns **False otherwise, in the resultant DataFrame.
  • gt() implements the behaviour of the binary relational operator '>'.
  • The list of relational operations supported by the DataFrame class of Python pandas library is listed in the following table:
DataFrame MethodDescription
eq()Equal to
neq()Not equal to
lt()Less than
le()Less than or equal to
gt()Greater than
ge()Greater than or equal to

Example

python
import pandas as pd

d1 = [(2, 1, 3),

      (5, 9, 4),

      (2, 5, 9)];

d2 = [(1, 2, 3),

      (4, 5, 6),

      (7, 8, 9)];

df1 = pd.DataFrame(data=d1);

df2 = pd.DataFrame(data=d2);

comparisionResult = df1.gt(df2);

print("DataFrame One:");

print(df1);

print("DataFrame Two:");

print(df2);

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

print(comparisionResult);

Output

Output
DataFrame One:

   0  1  2

0  2  1  3

1  5  9  4

2  2  5  9

DataFrame Two:

   0  1  2

0  1  2  3

1  4  5  6

2  7  8  9

DataFrame One gt(<) DataFrame Two:

       0      1      2

0   True  False  False

1   True   True  False

2  False  False  False