I have Dataframe as below.

name    value     id
A       123         1
B       345         5
C       567         4
D       789         2

I need to create a dictionary of the form below


I tried below code, but it makes 'name' as the key.


How to get the dictionary of the form i have mention? Do i need to iterate through rows?


1 Answer 1


Check this:

data_set.to_dict(orient = 'records')
  • 1
    $\begingroup$ Thank you. this is exactly what i needed $\endgroup$
    – Harshith
    Aug 19, 2019 at 7:04

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.