Signup/Sign In
PUBLISHED ON: MARCH 19, 2021

Pandas DataFrame le() Method

In this tutorial, we will learn the Python pandas DataFrame.le() method. This method is used to get less than or equal to of dataframe and other, element-wise (binary operator get). It returns the DataFrame of bool that is the result of the comparison.

The below shows the syntax of the DataFrame.le() method.

Syntax

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

Parameters

other: It can be any single or multiple element data structure, or list-like object, for example, scalar, sequence, Series, or DataFrame.

axis:'0' represents the index and '1' represents the columns and the default is columns. It represents whether to compare by the index axis or column axis.

level: It represents the int or label. It broadcasts across a level, matching Index values on the passed MultiIndex level.

Example: Comparing the DataFrame with the constant using the DataFrame.le() Method

Here, we are comparing with a scalar using the DataFrame.le() method that returns a bool-type dataframe.

#importing pandas as pd
import pandas as pd
#importing numpy as np
import numpy as np
#creating the DataFrame
df=pd.DataFrame({"A":[200,500],"B":[60,250],"C":[150,1]})
print("--------The DataFrame is---------")
print(df)
print("----After applying le function-----")
print(df.le(200))


--------The DataFrame is---------
A B C
0 200 60 150
1 500 250 1
----After applying le function-----
A B C
0 True True True
1 False False True

Example: Comparing the DataFrame with the Series using the DataFrame.le() Method

Here, we are comparing dataframe with a Series by using the DataFrame.le() method. See the below example.

#importing pandas as pd
import pandas as pd
#creating the DataFrame
df=pd.DataFrame({"A":[200,500],"B":[60,250],"C":[150,1]})
print("--------The DataFrame is---------")
print(df)
series = pd.Series([150, 200,150]) 
print("----After applying le function-----")
print(df.le(series,axis=0))


--------The DataFrame is---------
A B C
0 200 60 150
1 500 250 1
----After applying le function-----
A B C
0 False True True
1 False False True
2 False False False

Example: Comparing the DataFrame with the other DataFrame using the DataFrame.le() Method

Here, we are comparing dataframe with other DataFrame using the DataFrame.le() method. See the below example.

#importing pandas as pd
import pandas as pd
#creating the DataFrame
df_1=pd.DataFrame({"A":[200,500],"B":[60,250],"C":[150,1]})
print("--------The first DataFrame is---------")
print(df_1)
df_2=pd.DataFrame({"A":[200,550],"B":[65,251],"C":[100,10]})
print("--------The second DataFrame is---------")
print(df_2)
print("----After applying le function-----")
print(df_1.le(df_2))


--------The first DataFrame is---------
A B C
0 200 60 150
1 500 250 1
--------The second DataFrame is---------
A B C
0 200 65 100
1 550 251 10
----After applying le function-----
A B C
0 True True False
1 True True True

Conclusion:

In this tutorial, we learned the Python pandas DataFrame.le() method. We learned the syntax, parameters and applying this method on the DataFrame to understandd the DataFrame.le() method.



About the author:
I like writing about Python, and frameworks like Pandas, Numpy, Scikit, etc. I am still learning Python. I like sharing what I learn with others through my content.