neversaint
neversaint

Reputation: 63994

How to convert dictionary of list into data frame in Pandas

I have the following dictionary of list:

my_dol = { "01_718":  [232,211,222],
           "02_707":  [404,284,295],
           "03_708":  [221,209,220]}

How can I convert it to data frame like this::

  01_718   02_707  03_708 
  232      404     221
  211      284     209
  222      295     220

Upvotes: 2

Views: 397

Answers (1)

EdChum
EdChum

Reputation: 394003

Use from_dict:

In [54]:
my_dol = { "01_718":  [232,211,222],
           "02_707":  [404,284,295],
           "03_708":  [221,209,220]}
pd.DataFrame.from_dict(my_dol)
Out[54]:
   01_718  02_707  03_708
0     232     404     221
1     211     284     209
2     222     295     220

Actually as the values are already array-like then it'll just work as the data arg to DataFrame ctor:

In [55]:
my_dol = { "01_718":  [232,211,222],
           "02_707":  [404,284,295],
           "03_708":  [221,209,220]}
pd.DataFrame(my_dol)

Out[55]:
   01_718  02_707  03_708
0     232     404     221
1     211     284     209
2     222     295     220

Upvotes: 2

Related Questions