Here is my data
cars = {'Brand': ['Honda Civic','Toyota Corolla','Ford Focus','Audi A4'],
'Price': [22000,25000,27000,35000]
}
df = pd.DataFrame(cars, columns = ['Brand', 'Price'])
I would like to input data to be filtered using i via pandas query.
While this works-
i = 'Honda Civic'
df[df['Brand'] == i]
While, if I try do it via query as shown below, it doesn't work -
i = 'Honda Civic'
(df
.query('Brand' == i))
How should I modify the query command to make it work?
(df .query('Brand' == @i)- doesnt workdf.query("Brand==@i")remove the quotes aroundBrandi = ['Honda Civic'] (df. query(Brand==@i)). I still get invalid syntax error :(df.query("Brand==@i"). and no need to wrap it in a list, if it is just one item.