Home » Pandas DataFrame.query()

Pandas DataFrame.query()

by Online Tutorials Library

Pandas DataFrame.query()

For analyzing the data, we need a lot of filtering operations. Pandas provide a query() method to filter the DataFrame.

It offers a simple way of making the selection and also capable of simplifying the task of index-based selection.

Syntax

Parameters

  • expr: Refers to an expression in string form to filter data.
  • inplace: If the value is True, it makes the changes in the original DataFrame.
  • kwargs: Refers to the other keyword arguments.

Return

It returns a DataFrame that results from the query expression.

Note: This method only works if the column name doesn’t have any empty spaces. You can replace the spaces in column names with ‘_’

Example1

Output

XYZ Z  011010  

Next TopicDataFrame.rename()

You may also like