I have the following code in python.
d1=pd.read_excel("data1.xlsx",sheetname=0, index_col = "Time", parse_date=True)
d1=d1.sort_index()
for val in d1.columns:
start_his=d1[str(val)]
The data1.xlsx contains
Time Start High Low End 5
05/12/2014 28,000 31,500 27,400 29,900 29,740.00
28/11/2014 29,450 29,450 27,950 28,250 30,190.00
21/11/2014 30,500 30,500 28,100 29,300 30,840.00
14/11/2014 31,750 31,750 29,600 29,900 31,200.00
07/11/2014 32,250 32,750 30,500 31,350 31,620.00
31/10/2014 31,800 33,000 31,300 32,150 32,230.00
24/10/2014 31,300 32,750 30,800 31,500 32,680.00
17/10/2014 32,000 32,150 30,550 31,100 33,270.00
10/10/2014 34,550 34,550 32,000 32,000 33,920.00
02/10/2014 35,000 35,000 32,400 34,400 34,560.00
26/09/2014 34,600 35,000 33,600 34,400 34,770.00
19/09/2014 34,350 34,750 32,200 34,450 35,070.00
I got the Output for the first 4 columns(Start, High, Low & End) but 5th Columns shows key error. If I change the numeric '5' to any other value (i.e., Alpha numeric) it works correctly but it is not accepting numbers in column header. Please help to solve this error.
and i got the error is
Traceback (most recent call last):
File "ARIMA & Byesian.py", line 94, in <module>
start_his=d1[str(val)]
File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 1780, in __getitem__
return self._getitem_column(key)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 1787, in _getitem_column
return self._get_item_cache(key)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py", line 1068, in _get_item_cache
values = self._data.get(item)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/internals.py", line 2849, in get
loc = self.items.get_loc(item)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/index.py", line 1402, in get_loc
return self._engine.get_loc(_values_from_object(key))
File "pandas/index.pyx", line 134, in pandas.index.IndexEngine.get_loc (pandas/index.c:3812)
File "pandas/index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas/index.c:3692)
File "pandas/hashtable.pyx", line 696, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12299)
File "pandas/hashtable.pyx", line 704, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12250)
KeyError: '5'
str(val)
and5
will be made'5'
. Useval
directly and reply with the results – Bhargav Rao♦ Dec 26 '14 at 12:00