Reputation: 55
i loaded a json file into a dataframe using pd.read_json. One of the column named Info has the data in the form of {'name': 'john', 'lname': 'buck', 'address': '101 N state'}
there are 3 other columns with normal value like id, date, post
Q - how to extract all the rows from a dataframe where lname = 'buck'
Upvotes: 0
Views: 310
Reputation: 1109
You can use pandas.io.json.json_normalize to flatten the Info column to separate columns in your dataframe.
from pandas.io.json import json_normalize
df_norm = json_normalize(df, 'Info', ['id', 'date', 'post'])
Then you can query the normalized dataframe as you wish:
df_norm.query("lname == 'buck'")
Upvotes: 1