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