Gt() Function Of Pandas DataFrame Class

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 Method

Description

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:

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:

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


Copyright 2023 © pythontic.com