Overview
- The lt() function is one of the binary relational operations supported by the pandas DataFrame class.
- After performing an element-wise comparison of two pandas DataFrame instances, the lt() method returns a DataFrame which has the comparison results as Boolean values.
- A value in the resultant DataFrame is True, if the element of the first DataFrame is less than the element of the second DataFrame. Otherwise the value is False.
- The set of relational operations supported by the DataFrame class of Python pandas library and their meanings are given below:
| Binary Operation Name/DataFrame method Name | 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
dataCollection1 = [(10, 20, 10),
(30, 40, 30),
(50, 60, 50)];
dataCollection2 = [(20, 10, 15),
(40, 35, 45),
(55, 65, 70)];
dataFrameOne = pd.DataFrame(data=dataCollection1);
dataFrameTwo = pd.DataFrame(data=dataCollection2);
comparisionResult = dataFrameOne.lt(dataFrameTwo);
print("DataFrame One:");
print(dataFrameOne);
print("DataFrame Two:");
print(dataFrameTwo);
print("DataFrame One lt(<) DataFrame Two:");
print(comparisionResult);Output
DataFrame One:
0 1 2
0 10 20 10
1 30 40 30
2 50 60 50
DataFrame Two:
0 1 2
0 20 10 15
1 40 35 45
2 55 65 70
DataFrame One lt(<) DataFrame Two:
0 1 2
0 True False True
1 True False True
2 True True True