如果我复制作为面板元素的数据框,我可以使用append方法成功更新它。但是,我无法成功更新面板元素的数据框。我如何更新面板元素的数据框?为什么不能将行追加到面板对象内的数据框?
这里是复制成功追加。
In [204]: pdata
Out[204]:
<class 'pandas.core.panel.Panel'>
Dimensions: 696 (items) x 1 (major_axis) x 6 (minor_axis)
Items axis: 01-Apr-2014 to 31-Oct-2014
Major_axis axis: 0 to 0
Minor_axis axis: Date to Start Price
In [198]: test = pdata['20-Aug-2014']
In [199]: test
Out[199]:
Date Deal End Price Security Start Position Start Price
0 20-Aug-2014 PE 25 CU FP 3 17.4
In [200]: port.ix[233]
Out[200]:
Date 20-Aug-2014
Security CU FP
Deal PE
Start Price 17.4
Start Position 3
End Price 25
Name: 233, dtype: object
In [201]: test.append(port.ix[233], ignore_index=True)
Out[201]:
Date Deal End Price Security Start Position Start Price
0 20-Aug-2014 PE 25 CU FP 3 17.4
1 20-Aug-2014 PE 25 CU FP 3 17.4
In [202]: test = test.append(port.ix[233], ignore_index=True)
In [203]: test
Out[203]:
Date Deal End Price Security Start Position Start Price
0 20-Aug-2014 PE 25 CU FP 3 17.4
1 20-Aug-2014 PE 25 CU FP 3 17.4
在这里,我尝试了面板的元素同样的事情,但它不工作:
In [204]: pdata
Out[204]:
<class 'pandas.core.panel.Panel'>
Dimensions: 696 (items) x 1 (major_axis) x 6 (minor_axis)
Items axis: 01-Apr-2014 to 31-Oct-2014
Major_axis axis: 0 to 0
Minor_axis axis: Date to Start Price
In [206]: pdata['20-Aug-2014'] = pdata['20-Aug-2014'].append(port.ix[233], ignore_index=True)
In [207]: pdata['20-Aug-2014']
Out[207]:
Date Deal End Price Security Start Position Start Price
0 20-Aug-2014 PE 25 CU FP 3 17.4
在这里,我尝试分配数据帧的修改拷贝到元素面板,这也不起作用:
In [208]: pdata['20-Aug-2014'] = test
In [209]: pdata['20-Aug-2014']
Out[209]:
Date Deal End Price Security Start Position Start Price
0 20-Aug-2014 PE 25 CU FP 3 17.4
如何我可以更新数据框是面板的元素吗?
感谢,
加托
原来这是非常低效的,甚至几千更新永远运行,所以我感兴趣,如果任何人有更好的答案。 – gatomulato