df.query('price > @limit') is evaluated inside a function that holds limit as a local variable. Why does this work?
Correct answer
B. The @ prefix resolves the name in the caller's scope instead of as a column label
17 views
B. The @ prefix resolves the name in the caller's scope instead of as a column label
17 views
Local variable interpolation in query relies on the @ sigil, which tells the expression evaluator to look the name up in the calling frame rather than among the frame's columns. This avoids building temporary strings and keeps evaluation vectorised. Column names that clash with Python keywords are wrapped in backticks instead.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.