Friday, March 27, 2020

Pandas dataFrame - Compare two rows and keep one if condition is met

Here I have two columns 'A' and 'B', I want to keep the row where the cell value in column 'A' is less than the corresponding cell value in column 'B'.



There are many ways to do this, but one of the easiest is to use the query() method to delete rows from a dataframe based on a conditional expression.


You can reset the index values using: reset_index(drop=True)


That is it!

No comments:

Post a Comment