Using the DataFrame.to_panel method

A multi-indexed DataFrame is comparable to a Panel. Hence, a multi-indexed DataFrame can be directly converted to a Panel:

In [75]: mIdx = pd.MultiIndex(levels = [['US', 'China'], [1990,2000, 2010]], labels=[[1,1,1,0,0,0],[0,1,2,0,1,2]])
In [76]: ChinaUSDF = pd.DataFrame({'Population(M)' : [1133.68, 1266.83, 1339.72, 249.62, 282.16, 309.35], GDB($B)': [390.28, 1198.48, 6988.47, 8900, 12680,14940]}, index=mIdx)
In [77]: ChinaUSDF.to_panel()
Out[77]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 2 (major_axis) x 3 (minor_axis)
Items axis: Population(M) to GDB($B)
Major_axis axis: China to US
Minor_axis axis: 1990 to 2010

The sources of the US/China economic data are the following sites:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset