Comparison with other methods
Example 1
In this example, we are using a mixture of NumPy and pandas method
Python3
# to calculate timing import numpy as np % % timeit # using mixture of numpy and pandas method df_new = df.iloc[np.where(df.name.isin(li))] |
Output:
756 µs ± 132 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
Example 2
In this example, we are using only the Pandas method
Python3
# to calculate time % % timeit li = [ 'Albert' , 'Louis' , 'John' ] # Pandas method only df[(df.points> 50 )&(~df.name.isin(li))] |
Output
1.7 ms ± 307 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
How to select rows from a dataframe based on column values ?
Prerequisite: Pandas.Dataframes in Python
In this article, we will cover how we select rows from a DataFrame based on column values in Python.
The rows of a Dataframe can be selected based on conditions as we do use the SQL queries. The various methods to achieve this is explained in this article with examples.