0

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'

1 Answer 1

1

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'")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.