[PYTHON] Search for variables in pandas.DataFrame and get the corresponding row.

There is a query () method as a method to get the line with the corresponding character string from pandas.DataFrame.

df.query('name == "Suzuki"')

Enter the target column name in the above name, and the search string enclosed in "" after ==.

However, I wanted to loop the character string searched by for in, so I had to put a variable.

Of course,

search_name = 'Suzuki'
df.query('name == search_name')

Will result in an error.

It seems that you can add @ to use variables in query (), so

search_name = 'Suzuki'
df.query('name == @search_name')

It's done.

Recommended Posts

Search for variables in pandas.DataFrame and get the corresponding row.
Select the required variables in TensorFlow and save / restore
Recursively search for files and directories in Python and output
Set the environment variables required for PySide (Qt4) and PyQt (Qt5)
Get and create nodes added and updated in the new version
Search for strings in Python
Get the MIME type in Python and determine the file format
Search for strings in files
How to get all the keys and values in the dictionary
Get the current date and time in Python, considering the time difference
Get the number of occurrences for each element in the list
Google search for the last line of the file in Python
Get the Ticker Symbol for US exchange listed stocks in Python
About the need for the first slash in the subscriber name and publisher name
Search the file name including the specified word and extension in the directory
Search for character strings in files [Comparison between Bash and PowerShell]
Get the title and delivery date of Yahoo! News in Python
Format the Git log and get the committed file name in csv format
Get the desktop path in Python
Get the script path in Python
Get and visualize google search trends
Get the desktop path in Python
Get the host name in Python
Get the query string (query string) in Django
Vectorize sentences and search for similar sentences
Results that did not get caught in the search with this word
Get, test, and submit test cases on the command line in the AtCoder contest
How to get the date and time difference in seconds with python
python> array> Determine the number and initialize> mylist = [idx for idx in range (10)] / mylist = [0 for idx in range (10)] >> mylist = [0] * 10
Search for Twitter keywords with tweepy and write the results to Excel
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
Look up the names and data of free variables in function objects
Get and convert the current time in the system local timezone with python
What are the "pipeline" and "{...}" in the Jenkins Pipeline pipeline {...} (for Groovy beginners, for experienced languages)
Get the key for the second layer migration of JSON data in python
Get the client's IP address in Django
Implement the shortest path search for the maze
Get date and time in specified format
Search for files with the specified extension
Search and play YouTube videos in Python
Change the list in a for statement
Description method for reusing variables in shellscript
Get query parameters for GET requests in Django
MongoDB for the first time in Python
I can't get the element in Selenium!
Get a token for conoha in python
In search of the fastest FizzBuzz in Python
Find it in the procession and edit it
Get the EDINET code list in Python
(For myself) Flask_3 (form, POST and GET)
Get the address from latitude and longitude
[Reinforcement learning] Search for the best route
I can't use the "next_results" parameter in the Twitter API Search API! ?? Causes and remedies
I want to get the file name, line number, and function name in Python 3.4
Get the last element of the array by splitting the string in Python and PHP