In [63]:
yahoo['Range'] = yahoo['High']-yahoo['Low']
yahoo['ATR1'] = abs(yahoo['Prev Close']-yahoo['High'])
yahoo['ATR2'] = abs(yahoo['Prev Close']-yahoo['Low'])
yahoo
<class 'pandas.core.panel.Panel'>
Dimensions: 34 (items) x 804 (major_axis) x 14 (minor_axis)
Items axis: Open to Gap
Major_axis axis: 2010-12-13 00:00:00 to 2014-02-24 00:00:00
Minor_axis axis: AA to XOM
我已經在那裏我已經創建項目(列)範圍,ATR1和ATR2基本的數學函數max()幫助:在面板
我想創建上述面板其他項目(列)... TR,並提到這兩個選項中類似的職位
yahoo['TR'] = yahoo[['Range', 'ATR1', 'ATR2']].max(axis=1)
#yahoo['TR'] = yahoo[['Range', 'ATR1', 'ATR2']].apply(max, axis=1)
我曾經嘗試都,但得到的錯誤
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-64-15309b584b96> in <module>()
----> 1 yahoo['TR'] = yahoo[['Range', 'ATR1', 'ATR2']].max(axis=1)
2
3 #yahoo['TR'] = yahoo[['Range', 'ATR1', 'ATR2']].apply(max, axis=1)
4
C:\Anaconda\lib\site-packages\pandas\core\panel.pyc in __getitem__(self, key)
250 if isinstance(self._info_axis, MultiIndex):
251 return self._getitem_multilevel(key)
--> 252 return super(Panel, self).__getitem__(key)
253
254 def _getitem_multilevel(self, key):
C:\Anaconda\lib\site-packages\pandas\core\generic.pyc in __getitem__(self, item)
975
976 def __getitem__(self, item):
--> 977 return self._get_item_cache(item)
978
979 def _get_item_cache(self, item):
C:\Anaconda\lib\site-packages\pandas\core\generic.pyc in _get_item_cache(self, item)
979 def _get_item_cache(self, item):
980 cache = self._item_cache
--> 981 res = cache.get(item)
982 if res is None:
983 values = self._data.get(item)
TypeError: unhashable type: 'list'
我發佈了這個問題最初沒有意識到這是一個面板而不是數據框。這兩行代碼是數據框的解決方案,但在這裏不起作用。
基本上data.max(軸= 1) – YXD