Signup/Sign In
PUBLISHED ON: MARCH 19, 2021

Pandas DataFrame lt() Method

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

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

Syntax

DataFrame.lt(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.lt() Method

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

#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)
print("----After applying lt function-----")
print(df.lt(200))


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

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

Here, we are comparing DataFrame with a Series using the DataFrame.lt() 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 lt function-----")
print(df.lt(series,axis=0))


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

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

Here, we are comparing DataFrame with other DataFrame using the DataFrame.lt() method.

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


----After applying lt function-----
A B C
0 False True False
1 True True True

Conclusion:

In this tutorial, we learned the Python pandas DataFrame.lt() method. We learned the syntax, parameters and applying this method on the DataFrame to understand the DataFrame.lt() 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.