Search code examples
pythonpython-3.xpandasdataframeta-lib

getting some error while putting some dataframes in TA-Lib library, don't know what to do next


I was putting some dataframe in the ta-lib library to detect engulfing pattern but this error shows up which i don't know what it means please help

import pandas as pd
import talib as tb

bnkin = pd.read_csv("BANKINDIA.csv")
print(bnkin)

integer = tb.CDLENGULFING(bnkin['open'], bnkin['high'], bnkin['low'], bnkin['close'])
print(integer)
Traceback (most recent call last):
  File "C:\Users\myads\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexes\base.py", line 3081, in get_loc   
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 4554, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 4562, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'open'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:/Users/myads/OneDrive/Desktop/technical_analysis/TAprg.py", line 29, in <module>
    integer = tb.CDLENGULFING(bnkin['open'], bnkin['high'], bnkin['low'], bnkin['close'])
  File "C:\Users\myads\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\frame.py", line 3024, in __getitem__      
    indexer = self.columns.get_loc(key)
  File "C:\Users\myads\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexes\base.py", line 3083, in get_loc
    raise KeyError(key) from err
KeyError: 'open'

BANKINDIA.csv:-


Solution

  • You are looking for a column 'open', but your csv has a column 'Open', hence the key error.