dhruv kadia
dhruv kadia

Reputation: 55

how to read data frame having multiple json value in same columns

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

Answers (1)

dportman
dportman

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

Related Questions