使用pd.core.panelnd我可以构建一个带有任意轴名称的5D面板,例如:
import pandas as pd
import numpy as np
axis_1 = pd.Index(np.arange(0, 4), name='axis_1')
axis_2 = pd.Index(np.arange(0, 5), name='axis_2')
axis_3 = pd.Index(np.arange(0, 6), name='axis_3')
axis_4 = pd.Index(np.arange(0, 7), name='axis_4')
axis_5 = pd.Index(np.arange(0, 8), name='axis_5')
data = np.random.randn(axis_1.size, axis_2.size, axis_3.size, axis_4.size, axis_5.size,)
Panel5D = pd.core.panelnd.create_nd_panel_factory(klass_name=str('Example'), orders=['axis_1', 'axis_2', 'axis_3', 'axis_4', 'axis_5'], slices={'axis_2': 'labels', 'axis_3': 'items', 'axis_4': 'major_axis', 'axis_5': 'minor_axis'}, slicer=pd.Panel)
Dict5D = {}
for i, value in enumerate(np.arange(axis_1.size)):
Dict5D[value] = pd.Panel4D(data[i], labels=axis_2, items=axis_3, major_axis=axis_4, minor_axis=axis_5)
p5d = Panel5D(Dict5D)
因此,我的5D面板的摘要显示了轴的任意名称(axis_1,axis_2,...):
p5d
<class 'pandas.core.panelnd.Example'>
Dimensions: 4 (axis_1) x 5 (axis_2) x 6 (axis_3) x 7 (axis_4) x 8 (axis_5)
Axis_1 axis: 0 to 3
Axis_2 axis: 0 to 4
Axis_3 axis: 0 to 5
Axis_4 axis: 0 to 6
Axis_5 axis: 0 to 7
我的问题是我无法更改简单3D pd.Panel的轴名称:
data = np.random.randn(axis_1.size, axis_2.size, axis_3.size)
p3d = pd.Panel(data, axis_1, axis_2, axis_3)
我仍然可以使用常规命名(&#39; item&#39;,&#39; major_axis&#39;,&#39; minor_axis&#39;):
p3d
<class 'pandas.core.panel.Panel'>
Dimensions: 4 (items) x 5 (major_axis) x 6 (minor_axis)
Items axis: 0 to 3
Major_axis axis: 0 to 4
Minor_axis axis: 0 to 5
所以我的问题很简单,有没有办法改变3D面板的轴名称?
非常感谢!