我想创建具有不同数据帧的面板,我尝试编写一个函数来返回此面板。我使用了一些已编写的函数createNewDf(i)
,它根据给定的数值从现有数据返回dataFrame。
def panelCreation():
dp1 = Panel({})
for i in range(1,3):
name = 'X' + str(i)
name = createNewDf(i)
dp1.update(name) # This does not work
return dp1
我找不到代替dp1.update(name)
答案 0 :(得分:6)
如何从DataFrame的字典中创建Panel?
In [10]: dd = {}
In [11]: for i in range(1, 3):
....: name = 'X' + str(i)
....: dd[name] = DataFrame(np.random.randn(3,3))
....:
In [12]: Panel(dd)
Out[12]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 3 (major) x 3 (minor)
Items: X1 to X2
Major axis: 0 to 2
Minor axis: 0 to 2
类似于:
def panelCreation():
dd = {}
for i in range(1,3):
name = 'X' + str(i)
dd[name] = createNewDf(i)
return Panel(dd)