INVESTAR / StockAnalysisInPython

452 stars 411 forks source link

5장 DBUpdater Key Error 문의드립니다. #157

Open hyul0408 opened 1 year ago

hyul0408 commented 1 year ago

runfile('C:/python/DBUpdater.py_final.py', wdir='C:/python') C:\Users\minha\AppData\Roaming\Python\Python39\site-packages\pandas\io\sql.py:761: UserWarning: pandas only support SQLAlchemy connectable(engine/connection) ordatabase string URI or sqlite3 DBAPI2 connectionother DBAPI2 objects are not tested, please consider using SQLAlchemy warnings.warn( Traceback (most recent call last):

File "C:\Users\minha\AppData\Roaming\Python\Python39\site-packages\pandas\core\indexes\base.py", line 3621, in get_loc return self._engine.get_loc(casted_key)

File "pandas_libs\index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc

File "pandas_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc

File "pandas_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item

File "pandas_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item

KeyError: 'code'

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

Traceback (most recent call last):

File "C:\python\DBUpdater.py_final.py", line 168, in dbu.execute_daily()

File "C:\python\DBUpdater.py_final.py", line 135, in execute_daily self.update_comp_info()

File "C:\python\DBUpdater.py_final.py", line 58, in update_comp_info self.codes[df['code'].values[idx]] = df['company'].values[idx]

File "C:\Users\minha\AppData\Roaming\Python\Python39\site-packages\pandas\core\frame.py", line 3505, in getitem indexer = self.columns.get_loc(key)

File "C:\Users\minha\AppData\Roaming\Python\Python39\site-packages\pandas\core\indexes\base.py", line 3623, in get_loc raise KeyError(key) from err

KeyError: 'code'

INVESTAR commented 1 year ago

self.codes[df['code'].values[idx]]=df['company'].values[idx] 위 코드에서 키 에러가 발생한 것으로 봐서 company_info 테이블의 code 컬럼 쪽을 확인해 보시는 게 좋겠습니다.

https://github.com/INVESTAR/StockAnalysisInPython/issues/140#issuecomment-1053817757