0

I have a python dictionary,

Pydic = [{"GUID":"A","123":0.979,"234":0.975,"456":0.96,"674":0.77},
         {"GUID":"B","564":0.672,"999":0.654,"101":0.650,"001":0.491},
         {"GUID":"C","901":0.88,"687":0.800,"341":0.749,"888":0.660}]

I want to create a data frame that will have,

 GUID  Score_range  R1  R1_score  R2   R2_score  R3  R3_score R4  R4_score
  A    0.979-0.77  123  0.979    234    0.975   456   0.96    674  0.77
  B    0.672-0.491 564  0.672    999    0.654   101  0.650    001  0.491
  C    0.88-0.660  901  0.88     687    0.800   341  0.749    888  0.660

And once the data frame is created I want it to be written as csv in python?

Jennifer Therese
  • 623
  • 5
  • 15

1 Answers1

0

Probably a Duplicate of How do I convert this list of dictionaries to a csv file?

import csv

Pydic = [{"GUID":"A","123":0.979,"234":0.975,"456":0.96,"674":0.77},
         {"GUID":"B","564":0.672,"999":0.654,"101":0.650,"001":0.491},
         {"GUID":"C","901":0.88,"687":0.800,"341":0.749,"888":0.660}]

keys = Pydic[0].keys()
with open('people.csv', 'wb') as output_file:
    dict_writer = csv.DictWriter(output_file, keys)
    dict_writer.writeheader()
    dict_writer.writerows(Pydic)
Rohith Balaji
  • 714
  • 4
  • 16