Series.lt() is used to compare two rows and return a boolean value for each matching item.
Syntax: Series.lt (other, level = None, fill_value = None, axis = 0)
other: b> other series to be compared with
level: int or name of level in case of multi level
fill_value: Value to be replaced instead of NaN
axis: 0 or `index` to apply method by rows and 1 or `columns` to apply by columns.
Return type: b> Boolean series
Note: results are returned based on a comparison of the calling series & lt; other series.
To load the dataset used in the following example, click here.
In the following examples, the data frame being used contains data some NBA players. An image of the data frame before any operations is attached below.
Example # 1:
This example compares the Age and Weight columns using the .lt () method. Since the values in the weight columns are very large compared to the age column, therefore, the values are divisible by 10 first. The .dropna () method removes null rows before comparison to avoid errors.
As shown in the output image, the new column is True, where the value in the Age column is less, than Weight / 10.
Example # 2: Handling values NaN
In this example, two series are created using
pd.Series () . The series also contains a value of zero and therefore 10 is passed to the fill_value parameter to replace the zero values with 10. p>
As you can see from the results, the NaN values have been replaced with 5 and the comparison is done after the replacement, and the new values are used for comparison.
0 True 1 False 2 False 3 False 4 False 5 True 6 False 7 False 8 True dtype: bool
Pandas for Everyone: Python Data Analysis (Addison-Wesley Data & Analytics Series), 1st Edition. Pandas for Everyone brings together the practical knowledge and insights you need to solve real-worl...
The ability to identify patterns is an essential component of sensory intelli- gent machines. Pattern recognition is therefore an indispensible component of the so-called “Intelligent Control System...
Cracking the Coding Interview PDF: 189 Programming Questions and Solutions, 6th Edition. I am not a recruiter. I am a software engineer. And as such, I know what it's like to be asked to create ing...
Professional-quality code does more than just run without bugs. It’s clean, readable, and easy to maintain. To step up from a capable Python coder to a professional developer, you need to learn indu...