如果我複製作爲面板元素的數據框,我可以使用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