如何获取 pandas 中的面板项名称?
How to get panel item name in pandas?
我使用多个数据帧和字典在 pandas python 中创建了一个面板。
虽然我自己定义了 panal 项目名称,但我需要在另一段代码中将它们过滤掉。如何获取面板项名称?
我尝试使用面板属性命令,例如"axes"和"items"。然而 pandas 文档是相当基础的,并没有回答这个问题。
在我看来 panel
已被弃用 - 检查 docs,因此如果要使用 pandas
,一种可能的解决方案是 MultiIndex DataFrame
,如果可能,最好的方法是将字典转换为DataFrame
中的标量值以获得更好的性能和使用 pandas 函数。
然后检查:
print (df.columns.names)
和
print (df.index.names)
但如果要使用 panel
:
wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=pd.date_range('1/1/2000', periods=5),
minor_axis=pd.Series(['A', 'B', 'C', 'D'], name='foo'))
print (wp.axes[2].name)
foo
我使用多个数据帧和字典在 pandas python 中创建了一个面板。 虽然我自己定义了 panal 项目名称,但我需要在另一段代码中将它们过滤掉。如何获取面板项名称?
我尝试使用面板属性命令,例如"axes"和"items"。然而 pandas 文档是相当基础的,并没有回答这个问题。
在我看来 panel
已被弃用 - 检查 docs,因此如果要使用 pandas
,一种可能的解决方案是 MultiIndex DataFrame
,如果可能,最好的方法是将字典转换为DataFrame
中的标量值以获得更好的性能和使用 pandas 函数。
然后检查:
print (df.columns.names)
和
print (df.index.names)
但如果要使用 panel
:
wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=pd.date_range('1/1/2000', periods=5),
minor_axis=pd.Series(['A', 'B', 'C', 'D'], name='foo'))
print (wp.axes[2].name)
foo