How to create pandas dataframe from python dictionary?
Question: I have a python dictionary below:

    
    
    dict = {'stock1': (5,6,7), 'stock2': (1,2,3),'stock3': (7,8,9)};
    

I want to change dictionary to dataframe like:

[![enter image description
here](http://i.stack.imgur.com/puqs2.png)](http://i.stack.imgur.com/puqs2.png)

How to write the code?

I use:

    
    
    pd.DataFrame(list(dict.iteritems()),columns=['name','closePrice'])
    

But it will get wrong. Could anyone help?


Answer: You are overcomplicating the problem, just pass your dictionary into the
`DataFrame` constructor:

    
    
    import pandas as pd
    
    d = {'stock1': (5,6,7), 'stock2': (1,2,3),'stock3': (7,8,9)}
    print(pd.DataFrame(d))
    

Prints:

    
    
       stock1  stock2  stock3
    0       5       1       7
    1       6       2       8
    2       7       3       9
    

