-1

I am using python 3.5.1, Following shows data

import pandas as pd
import quandl
df = quandl.get('WIKI/GOOGL')
print(df.head())

I am doing following

import pandas as pd
import quandl
df = quandl.get('WIKI/GOOGL')

df = df[['Adj. Open','Adj. High','Adj. Low','Adj. Close','Adj. Volume',]]
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Close']) / df['Adj. Close']*100.0
df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. OPen']*100.0
df = df[['Adj. Close','HL_PCT','PCT_change','Adj. Volume']]

print(df.head())

but its showing following error

Traceback (most recent call last): File "C:\Users\jayram\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\indexes\base.py", line 2134, in get_loc return self._engine.get_loc(key) File "pandas\index.pyx", line 132, in pandas.index.IndexEngine.get_loc (pandas\index.c:4433) File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:4279) File "pandas\src\hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13742) File "pandas\src\hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13696) KeyError: 'Adj. OPen'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/jayram/Desktop/python/ok2", line 7, in df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. OPen']*100.0 File "C:\Users\jayram\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\frame.py", line 2059, in getitem return self._getitem_column(key) File "C:\Users\jayram\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\frame.py", line 2066, in _getitem_column return self._get_item_cache(key) File "C:\Users\jayram\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\generic.py", line 1386, in _get_item_cache values = self._data.get(item) File "C:\Users\jayram\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\internals.py", line 3543, in get loc = self.items.get_loc(item) File "C:\Users\jayram\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\indexes\base.py", line 2136, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas\index.pyx", line 132, in pandas.index.IndexEngine.get_loc (pandas\index.c:4433) File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:4279) File "pandas\src\hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13742) File "pandas\src\hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13696) KeyError: 'Adj. OPen'

Process finished with exit code 1

how to solve above error

ram om
  • 23
  • 1
  • 5

1 Answers1

1

change

df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. OPen']*100.0

to

df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. Open']*100.0
Aadhil Rushdy
  • 74
  • 1
  • 5
  • 3
    This would be better as a comment to the OP, as there is little long term value to the OP staying on SO since it is simply a typo. – Shawn Mehan Apr 05 '17 at 05:55