python - How to subset pandas DataFrame whose column values are lists? -


i have pandas dataframe df looks this:

a      b 0  ['a','b'] 1  ['c','d'] 2  ['a','c'] 3  ['b','d'] 4  ['a','d'] 

now, wish subset df selecting rows in 'a' belongs list in b, desired output being:

a      b 0  ['a','b'] 2  ['a','c']  4  ['a','d'] 

naively, tried df['a' in df['b']], doesn't seem work. how go doing this?

using apply 1 way filter.

in [39]: df[df['b'].apply(lambda x: 'a' in x)] out[39]:          b 0  0  [a, b] 2  2  [a, c] 4  4  [a, d] 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -