1

I have following dataset:

 {'Result': {
            'j': {'confirmed': true, 'version': '1'},
            'z': {'confirmed': false, 'version': '2'},
            'y': {'confirmed': true, 'version': '3'}
            },
         'D': 'null'
        }

And I need a table with columns : name (values j, z, y goes there) and confirmed (true or false goes there).

The closest thing I have tried is pd.Series(df), but it gives me something like:

j                    {'confirmed': true, 'version': '1'}
z                    {'confirmed': false, 'version': '2'}

How can I achieve only two accurate named columns?

1 Answer 1

1

You can use pd.DataFrame.from_dict() with orient='index', then reset_index() and rename() to set the previous index as column 'name':

pd.DataFrame.from_dict(dataset['Result'], orient='index').reset_index().rename(columns={'index': 'name'})

Yields:

   name confirmed version
0     j      true       1
1     y      true       3
2     z     false       2
Sign up to request clarification or add additional context in comments.

1 Comment

That's how I'd do it (-:

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.