0

I am struggling to convert a dictionary to a pandas dataframe. The dictionary has the following structure, where keys in the embedded dictionaries corresponds to column names of the table:

d = {{key1:v1,key2:v2},{key1:v3,key2:v4}}

The dictionaries within the main dictionary correspond to a row

Expected output:

   key1   key2
0   v1     v2
1   v3     v4

I have been trying to use DataFrame.from_dict() but could not make it work with that structure. Any idea how to do that efficiently?

Many thanks

Peslier53
  • 587
  • 1
  • 7
  • 21
  • `df = pd.DataFrame(d)` ? – jezrael Nov 07 '22 at 11:13
  • pd.DataFrame.from_dict(data, orient='index') – idan noyshul Nov 07 '22 at 11:19
  • The specific format given in the question is incorrect and indicates a set of dictionaries which would be rejected as unhashable. If a dictionary was properly defined then it could be converted using the @idan noshul approach. Or if instead it was written as `d = [{key1:v1,key2:v2},{key1:v3,key2:v4}]` then it could be converted using the @jezrael approach. – user19077881 Nov 07 '22 at 11:44

0 Answers0