【发布时间】:2023-03-17 16:33:01
【问题描述】:
这是来自pandas documentation 的示例。
import numpy as np
from pandas import *
randn = np.random.randn
data = { 'Label1' : Panel({ 'Item1' : DataFrame(randn(4, 3)) }),
'Label2' : Panel({ 'Item2' : DataFrame(randn(4, 2)) }) }
p4d = Panel4D(data)
子面板'Label1' 不应包含数据框'Item2',但是我得到了'Item1' 的副本:
In [29]: p4d.ix['Label1','Item1',:,:]
Out[29]:
0 1 2
0 0.283740 0.123377 0.122482
1 0.756958 0.618638 -1.732440
2 0.070798 -0.621752 -0.196360
3 0.462558 -1.023808 0.234144
In [30]: p4d.ix['Label1','Item2',:,:]
Out[30]:
0 1 2
0 0.283740 0.123377 0.122482
1 0.756958 0.618638 -1.732440
2 0.070798 -0.621752 -0.196360
3 0.462558 -1.023808 0.234144
反之亦然,'Label2' 和 'Item1'。
为什么函数 Panel4d 的行为是这样的?
我更喜欢空数据框(或至少一个用 NaN 填充的数据框)而不是副本。有没有办法做到这一点?
【问题讨论】: