Passing on new application of information I learned that was part of another question: Unable to query a local variable in pandas 0.14.0
Credit and thanks to user @choldgraf. I'm applying his answer from the above link differently.
Objective: To use a variable as the column name in a query
Failed examples:
import pandas as pd
fooframe = pd.DataFrame({'Size':['Large', 'Medium', 'Small', 'Tiny'], 'Color':[1, 2, 3, 4]})
myvar = 'Size'
subframe = fooframe.query("myvar == 'Large'")
The code above returns a key error for 'myvar'.
import pandas as pd
fooframe = pd.DataFrame({'Size':['Large', 'Medium', 'Small', 'Tiny'], 'Color':[1, 2, 3, 4]})
myvar = 'Size'
subframe = fooframe.query("@myvar == 'Large'")
The code above adds "@" before myvar in the query to reference myvar as a local variable. However, the code still returns an error.