Menu Close

How to filter rows of DataFrame with operator chaining with Python Pandas?

To filter rows of DataFrame with operator chaining with Python Pandas, we can use the data frame query method.

For instance, we write

df_filtered = df.query('a > 0 and 0 < b < 2')

to call df.query with the conditions we want for the values to return a new data frame with the filtered values.

Posted in Python, Python Answers