0

I'm trying to transform this complex object into a pandas dataframe

data={
    "customers": [
        {
            "a": 'true',
            "addresses": [{"city": "Park"}],
            "c": { "address1": "200"},
            "d": "[email protected]",
            "e": {"f": "sub"},
            "h": 100,
           
        }
    ]
}

I've tried several ways but none of them work.

df = pd.json_normalize(data,record_path='addresses',meta=['h'] ,record_prefix='adr'
                               ,errors='ignore')

I always get the same error

KeyError: "Key 'addresses' not found. If specifying a record_path, all elements of data should have the path."

0

1 Answer 1

1

Your first key is "customers":

df = pd.json_normalize(
    data=data.get("customers"),
    record_path="addresses",
    meta="h",
    record_prefix="adr"
)

print(df)
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.