python - Change indescriptive axis names of Pandas Panel and Panel4D -
the standard axis names of panel items, major_axis , minor_axis
in [2]: pd.panel() out[2]: <class 'pandas.core.panel.panel'> dimensions: 0 (items) x 0 (major_axis) x 0 (minor_axis) items axis: none major_axis axis: none minor_axis axis: none
that indescriptive hell, , gets worse panel4d, labels added fourth axis. there way change them during initialization? or can use pd.core.create_nd_panel_factory
create new panel4d factory different axis names?
edit: have is
out[3]: <class 'pandas.core.panel.panel'> dimensions: 0 (items) x 0 (major_axis) x 0 (minor_axis) x axis: none y axis: none z axis: none
since answer given in pandas access axis user-defined name old pandas version , not provide full functionality, how works:
from pandas.core.panelnd import create_nd_panel_factory pandas.core.panel import panel panel4d = create_nd_panel_factory( klass_name='panel4d', orders=['axis1', 'axis2', 'axis3', 'axis4'], slices={'labels': 'labels', 'axis2': 'items', 'axis3': 'major_axis', 'axis4': 'minor_axis'}, slicer=panel, stat_axis=2, ) def panel4d_init(self, data=none, axis1=none, axis2=none, axis3=none, axis4=none, copy=false, dtype=none): self._init_data(data=data, axis1=axis1, axis2=axis2, axis3=axis3, axis4=axis4, copy=copy, dtype=dtype) panel4d.__init__ = panel4d_init
it part of pandas source code reworked.
then
>>> panel4d(np.random.rand(4,4,4,4)) out[1]: <class 'pandas.core.panelnd.panel4d'> dimensions: 4 (axis1) x 4 (axis2) x 4 (axis3) x 4 (axis4) axis1 axis: 0 3 axis2 axis: 0 3 axis3 axis: 0 3 axis4 axis: 0 3
and in contrary answer given in pandas access axis user-defined name, instance of panel4d
functional , behaves instance of pandas.panel4d
. example can panel4d(np.empty((1,1,1,1)))[0]
whithout haveing exception thrown.
Comments
Post a Comment