python - Pandas: Querying an object column in dataframe -


i have following data frame

           q1  q2_1  q2_2 respid   value      q2         0   1     1     0      1     [1]     [1]         1   2     0     1      2     [2]     [2]         2   3     0     1      3     [2]     [2]         3   4     1     0      4     [1]     [1]         4   5     1     1      5  [1, 2]  [1, 2]         5   1     0     0      6      []      []         6   1     1     1      7  [1, 2]  [1, 2]         7   3     0     0      8      []      [] 

i can query columns single values df[df['q1']==1]. cannot df[1 in df['q2']].

you can use apply that:

df[df['q2'].apply(lambda x : 1 in x)] 

Comments