I have a dataframe as given below.
import pandas as pd
raw_data = {'score': [1,2,3],
'tags': [['apple','pear','guava'],['truck','car','plane'],['cat','dog','mouse']]}
df = pd.DataFrame(raw_data, columns = ['score', 'tags'])
df.query("score==1") gives the first row as result.
But df.query("tags='apple'") gives error.
How to write query for the column 'tags'.
querymethod is unable to evaluate your expression to handle this. To filter the df you'd need to dodf[df['tags'].apply(lambda x: 'apple' in x)]. Storing non-scalar values in a df is non-performant, you can't expect the usual pandas operations to work like normalqueryto handles lists