dataframe change size and the convert to panel python
Question: I have a question on how to change dataframe to a panel while changinig the
dimensions of the dataframe. Originally I have a data frame with 2000 rows and
784 colmuns:

    
    
    data=pd.DataFrame(np.random.randn(2000,784))
    data.shape
    (2000, 784)
    

I would like to turn each column into a 28*28 dataframe and then store this
into a panel like structure with the size (2000,28,28) or 2000 28 by 28
dataframes. Looking at some
[answers](http://stackoverflow.com/questions/17243186/assigning-dataframe-to-
panel-in-pandas), I tried:

    
    
    data_panel=pd.Panel(dict([ (i,data) for i in range(2000)]))
    data_panel
    <class 'pandas.core.panel.Panel'>
    Dimensions: 2000 (items) x 2000 (major_axis) x 784 (minor_axis)
    Items axis: 0 to 1999
    Major_axis axis: 0 to 1999
    Minor_axis axis: 0 to 783
    

But that is not what I want. The items axis is correct, but I would like the
major axis and minor axis to be 28 by 28.


Answer: What seems to be the problem? This works:

    
    
    import pandas as pd
    import numpy as np
    
    data = pd.DataFrame(np.random.randn(2000,784))
    
    panel = pd.Panel(data.values.reshape(2000, 28, 28))
    
    # In [49]: q.panel[42].shape
    # Out[49]: (28, 28)
    
    # In [51]: q.panel
    # Out[51]:
    # <class 'pandas.core.panel.Panel'>
    # Dimensions: 2000 (items) x 28 (major_axis) x 28 (minor_axis)
    # Items axis: 0 to 1999
    # Major_axis axis: 0 to 27
    # Minor_axis axis: 0 to 27
    

