TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Pandas DataFrame.query()

Pandas DataFrame.query() with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.

<< Back to PANDAS

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

DataFrame.query(expr, inplace=False, **kwargs)

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

info = pd.DataFrame({'X': range(1, 6),
                    'Y': range(10, 0, -2),
                    'Z Z': range(10, 5, -1)})
info
info.query('X > Y')
info[info.X > info.Y]
info[info.Y == info['Z Z']]

Output

	X	Y			Z Z
0	1	10			10

Next TopicDataFrame.rename()




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf