@@ -798,3 +798,119 @@ method:
798
798
major_axis = date_range(' 1/1/2000' , periods = 5 ),
799
799
minor_axis = [' a' , ' b' , ' c' , ' d' ])
800
800
panel.to_frame()
801
+
802
+ Panel4D (Experimental)
803
+ ----------------------
804
+
805
+ ``Panel4D `` is a 4-Dimensional named container very much like a ``Panel ``, but
806
+ having 4 named dimensions. It is intended as a test bed for more N-Dimensional named
807
+ containers.
808
+
809
+ - **labels **: axis 0, each item corresponds to a Panel contained inside
810
+ - **items **: axis 1, each item corresponds to a DataFrame contained inside
811
+ - **major_axis **: axis 2, it is the **index ** (rows) of each of the
812
+ DataFrames
813
+ - **minor_axis **: axis 3, it is the **columns ** of each of the DataFrames
814
+
815
+
816
+ ``Panel4D `` is a sub-class of ``Panel ``, so most methods that work on Panels are
817
+ applicable to Panel4D.
818
+
819
+ Construction of Panel4D works in a very similar manner to a ``Panel ``
820
+
821
+ From 4D ndarray with optional axis labels
822
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
823
+
824
+ .. ipython :: python
825
+
826
+ p4d = Panel4D(randn(2 , 2 , 5 , 4 ),
827
+ labels = [' Label1' ,' Label2' ],
828
+ items = [' Item1' , ' Item2' ],
829
+ major_axis = date_range(' 1/1/2000' , periods = 5 ),
830
+ minor_axis = [' A' , ' B' , ' C' , ' D' ])
831
+ p4d
832
+
833
+
834
+ From dict of Panel objects
835
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
836
+
837
+ .. ipython :: python
838
+
839
+ data = { ' Label1' : Panel({ ' Item1' : DataFrame(randn(4 , 3 )) }),
840
+ ' Label2' : Panel({ ' Item2' : DataFrame(randn(4 , 2 )) }) }
841
+ Panel4D(data)
842
+
843
+ Note that the values in the dict need only be **convertible to Panels **.
844
+ Thus, they can be any of the other valid inputs to Panel as per above.
845
+
846
+ Slicing
847
+ ~~~~~~~
848
+
849
+ Slicing works in a similar manner to a Panel. ``[] `` slices the first dimension.
850
+ ``.ix `` allows you to slice abitrarily and get back lower dimensional objects
851
+
852
+ .. ipython :: python
853
+
854
+ p4d[' Label1' ]
855
+
856
+ 4D -> Panel
857
+
858
+ .. ipython :: python
859
+
860
+ p4d.ix[:,:,:,' A' ]
861
+
862
+ 4D -> DataFrame
863
+
864
+ .. ipython :: python
865
+
866
+ p4d.ix[:,:,0 ,' A' ]
867
+
868
+ 4D -> Series
869
+
870
+ .. ipython :: python
871
+
872
+ p4d.ix[:,0 ,0 ,' A' ]
873
+
874
+ Transposing
875
+ ~~~~~~~~~~~
876
+
877
+ A Panel4D can be rearranged using its ``transpose `` method (which does not make a
878
+ copy by default unless the data are heterogeneous):
879
+
880
+ .. ipython :: python
881
+
882
+ p4d.transpose(3 , 2 , 1 , 0 )
883
+
884
+ PanelND (Experimental)
885
+ ----------------------
886
+
887
+ PanelND is a module with a set of factory functions to enable a user to construct N-dimensional named
888
+ containers like Panel4D, with a custom set of axis labels. Thus a domain-specific container can easily be
889
+ created.
890
+
891
+ The following creates a Panel5D. A new panel type object must be sliceable into a lower dimensional object.
892
+ Here we slice to a Panel4D.
893
+
894
+ .. ipython :: python
895
+
896
+ from pandas.core import panelnd
897
+ Panel5D = panelnd.create_nd_panel_factory(
898
+ klass_name = ' Panel5D' ,
899
+ axis_orders = [ ' cool' , ' labels' ,' items' ,' major_axis' ,' minor_axis' ],
900
+ axis_slices = { ' labels' : ' labels' , ' items' : ' items' , ' major_axis' : ' major_axis' , ' minor_axis' : ' minor_axis' },
901
+ slicer = Panel4D,
902
+ axis_aliases = { ' major' : ' major_axis' , ' minor' : ' minor_axis' },
903
+ stat_axis = 2 )
904
+
905
+ p5d = Panel5D(dict (C1 = p4d))
906
+ p5d
907
+
908
+ # print a slice of our 5D
909
+ p5d.ix[' C1' ,:,:,0 :3 ,:]
910
+
911
+ # transpose it
912
+ p5d.transpose(1 ,2 ,3 ,4 ,0 )
913
+
914
+ # look at the values & dim
915
+ p5d.values.shape
916
+ p5d.values.ndim
0 commit comments