Le() Function Of Pandas DataFrame Class


  • The le() method is equivalent to the <= operator, and it implements the binary relational operation of "less than or equal to".
  • When le() is called on a pandas DataFrame instance DF1, it compares each element with corresponding element from another DataFrame DF2.
  • If the element from DF1 is less than or equal to the value of the element from DF2, le() returns True in the resultant DataFrame. Returns False otherwise, in the resultant DataFrame.



# Example Python program that compares two pandas DataFrames using the method DataFrame.le()

import pandas as pd


# Lists of tuples of string literals

stringsCollection1 = [('A', 'B', 'C'),

                      ('D', 'E', 'F'),

                      ('G', 'H', 'I')];


stringsCollection2 = [('B', 'A', 'D'),

                      ('A', 'E', 'F'),

                      ('J', 'C', 'K')];


# Create dataframes using lists of tuples

dataFrame1 = pd.DataFrame(data=stringsCollection1);

dataFrame2 = pd.DataFrame(data=stringsCollection2);


# Compare two data frames using le()

comparisionResult = dataFrame1.le(dataFrame2);


print("DataFrame One:");



print("DataFrame Two:");



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




DataFrame One:

   0  1  2

0  A  B  C

1  D  E  F

2  G  H  I

DataFrame Two:

   0  1  2

0  B  A  D

1  A  E  F

2  J  C  K

DataFrame One le(<) DataFrame Two:

       0      1     2

0   True  False  True

1  False   True  True

2   True  False  True

Copyright 2022 © pythontic.com