0

i have a json file like below..

{
"assetPropertyValues" : {
    "A001234": {
        "PV": 1.2345
    },
    "A001235": {
        "PV": 1.234678
    },
    "A001236": {
        "PV": 1.234678
    }
 }
}

I want to display this data as below..

                 PV
A001234          1.2345
A001235          1.2345678
A001236          1.2345678

i don't have any idea how to do this..please help me out.. Thank you..

2
  • SO requires you to first work on the problem yourself and not just post the exercises directly. See stackoverflow.com/help/how-to-ask. Commented Aug 14, 2021 at 19:17
  • Yes sir..I have tried that problem using json_normalize() and I went through some videos and documents..I didn't get the answer like this..I should have post that output too..as this is my first question posting in stack over flow , I don't know how to post..I will make it better from the next time.. thank you so much sir. Commented Aug 15, 2021 at 7:28

1 Answer 1

2

We can use DataFrame.from_dict and orient='index':

v = {
    "assetPropertyValues": {
        "A001234": {
            "PV": 1.2345
        },
        "A001235": {
            "PV": 1.234678
        },
        "A001236": {
            "PV": 1.234678
        }
    }
}

df = pd.DataFrame.from_dict(v['assetPropertyValues'], orient='index')

Or when reading from a file with json.load:

import json

import pandas as pd

with open('source.json') as f:
    df = pd.DataFrame.from_dict(
        json.load(f)['assetPropertyValues'],
        orient='index'
    )

df:

               PV
A001234  1.234500
A001235  1.234678
A001236  1.234678
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.