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
I have the above panel where i have created Items (Columns) Range, ATR1, and ATR2
i would like to create another item (Column) ... TR and was referred to these 2 options in a similar post
yahoo['TR'] = yahoo[['Range', 'ATR1', 'ATR2']].max(axis=1)
#yahoo['TR'] = yahoo[['Range', 'ATR1', 'ATR2']].apply(max, axis=1)
i have tried both but get the error
---------------------------------------------------------------------------
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'
i posted this question originally failing to realize that this was a panel and not a dataframe. the two lines of code are the solution for a dataframe but do not work here.