title: Covert python OrderedDict to dataframe
body: <p>My record, an <code>OrderedDict</code>, looks like this:</p>
  
  <p><code>my_record = OrderedDict([ (u'FIR_ID', '111249'), (u'FIR_TYPE', 'ORG')])</code></p>
  
  <p>I need to load this to a database, so I'd like to convert the data set into a dataframe, and then, into a CSV file, to facilitate db load. But, when I do <code>type(my_record)</code>, I get:</p>
  
  <pre><code>&lt;class 'pg.mod.results'&gt;
  </code></pre>
  
  <p>which means it is a class object. If it was of type <code>collections.OrderedDict</code>, I could just do a <code>DataFrame(my_record)</code>. I am using Python 2.x. What can I convert this <code>OrderedDict</code> to a <code>DataFrame</code>?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Thanks to nosklo's code, the errors are gone; the column headers are there but the values are missing. I extracted 10 records which look like this:</p>
  
  <pre><code>[&lt;ravenpackapi.models.results.Result at 0x118caadd0&gt;,
   &lt;ravenpackapi.models.results.Result at 0x118caad90&gt;,
   &lt;ravenpackapi.models.results.Result at 0x118e1a950&gt;,
  ...,  &lt;ravenpackapi.models.results.Result at 0x118da8750&gt;]
  </code></pre>
  
  <p>Then, the csv.DictWriter() produces a csv with this content:</p>
  
  <pre><code>&lt;Field: TIMESTAMP_UTC&gt;,&lt;Field: RP_STORY_ID&gt;,&lt;Field: RP_ENTITY_ID&gt;,...,&lt;Field: ENTITY_TYPE&gt;,,,,,,,,,,,,,,,
  </code></pre>
  
  <p>which looks like the complete list of keys. And there are many rows of ',,,,' at the end of the file indicating that values are missing.</p>
  
  <p><strong>Update</strong></p>
  
  <p>My current code is this:</p>
  
  <pre><code>records = list(records)
  with open('/Users/.../.../RP_test_5.txt', 'w') as f:
      cf = csv.DictWriter(f, 
          ravenpackapi.models.fields.ANALYTICS_FIELDS,
          extrasaction='ignore') 
      cf.writeheader()
      cf.writerows(r.data for r in records)
  </code></pre>
  
  <p>Since the values are missing, I tried:</p>
  
  <pre><code>for r in records: r.data
  </code></pre>
  
  <p>which successfully gave me the dictionary I need. So I don't understand why, I can't write any values to my csv. Could it be that </p>
  
  <pre><code>ravenpackapi.models.fields.ANALYTICS_FIELDS
  </code></pre>
  
  <p>gives me</p>
  
  <pre><code>[&lt;Field: TIMESTAMP_UTC&gt;,
   &lt;Field: RP_STORY_ID&gt;,
   &lt;Field: RP_ENTITY_ID&gt;,
   &lt;Field: ENTITY_TYPE&gt;,...
  </code></pre>
  
  <p>whereas, <strong>r.data</strong> from</p>
  
  <pre><code>for r in records: r.data
  </code></pre>
  
  <p>gives me</p>
  
  <pre><code> {u'RP_ENTITY_ID': u'91C82E',
   u'RP_POSITION_ID': None,
   u'RP_SOURCE_ID': u'C98333',
   u'RP_STORY_EVENT_COUNT': 17,
   u'RP_STORY_EVENT_INDEX': 5,
   u'RP_STORY_ID': u'54F16F66850FB15F838629FD0C41F1CD',
   u'SOURCE_NAME': u'Ticker Report',
   u'SUB_TYPE': None,
   u'TIMESTAMP_UTC': u'2018-06-30 00:03:10.457',...,}
  </code></pre>
  
  <p>which are in different order, and/or, the keys are formatted differently?</p>
  
  <p><code>u'TIMESTAMP_UTC'</code> versus <code>&lt;Field: TIMESTAMP_UTC&gt;</code></p>
  
  <p><strong>This worked</strong></p>
  
  <pre><code>records = list(records)
  
  for r in records: r.data
  
  with open('/Users/.../RP_test_6.txt', 'w') as f:
      cf = csv.DictWriter(f, 
          r.data.keys(),
          extrasaction='ignore') 
      cf.writeheader()
      cf.writerows(r.data for r in records)
  </code></pre>
  
  <p>I am sure there are better ways than</p>
  
  <pre><code>for r in records: r.data
  </code></pre>
  
  <p>and </p>
  
  <pre><code>r.data.keys()
  </code></pre>
  
  <p>Ideas?</p>