Reputation: 431
Given a dataframe df['serialnumber', 'basicinfo'], the column "basicinfo" is a dict {'name': xxx, 'model': xxx, 'studyid': xxx}.
Is there an easy way to filter this dataframe by the dict key "model"?
We can do this filtered by 'serialnumber' if it is integer:
df = df[df.serialnumber == <value>]
How to do that for dict column?
Upvotes: 4
Views: 3900
Reputation: 4738
You won't get the vectorized operations directly. But you could use apply
to get the dictionary value from.
df = df[df.basicinfo.apply(lambda x: x['model'] == <value>)]
Upvotes: 9