I've run into a situation where I can query a pandas dataframe with column names and string literals in the query string
import pandas as pd
data = pd.DataFrame([list('aba'),
list('xyz')],
columns=['A', 'B', 'C'])
data.query("A == 'a'")
# A B C
# 0 a b a
data.query("A.eq('a')")
# A B C
# 0 a b a
but when I use a variable substitution instead of the column name, I get errors.
x = 'A'
data.query("@x == 'a'")
# KeyError: 'False: boolean label can not be used without a boolean index'
data.query("@x.eq('a')")
# AttributeError: 'str' object has no attribute 'eq'
What's going on?