|
小白想自学python做量化,看到网络上有位老师的现成代码如下:
stock_data = pd.read_csv('/Python/data/code_data/data/stock_data_sample.csv',
encoding='gbk') # 此处填入数据在本地的路径
stock_data.columns = [i.encode("utf8") for i in stock_data.columns]
stock_data['交易日期'] = pd.to_datetime(stock_data['交易日期'])
....后面部分省略
我复制一模一样的代码
一跑程序,出现下列错误,求高手给出原因!!!
C:\Python\Python36\python.exe C:/Python/data/code_data/code/select_stocks.py
Traceback (most recent call last):
File "C:\Python\Python36\lib\site-packages\pandas\core\indexes\base.py", line 2442, in get_loc
return self._engine.get_loc(key)
File "pandas\_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5280)
File "pandas\_libs\index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5126)
File "pandas\_libs\hashtable_class_helper.pxi", line 1210, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20523)
File "pandas\_libs\hashtable_class_helper.pxi", line 1218, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20477)
KeyError: '交易日期'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Python/data/code_data/code/select_stocks.py", line 12, in <module>
stock_data['交易日期'] = pd.to_datetime(stock_data['交易日期'])
File "C:\Python\Python36\lib\site-packages\pandas\core\frame.py", line 1964, in __getitem__
return self._getitem_column(key)
File "C:\Python\Python36\lib\site-packages\pandas\core\frame.py", line 1971, in _getitem_column
return self._get_item_cache(key)
File "C:\Python\Python36\lib\site-packages\pandas\core\generic.py", line 1645, in _get_item_cache
values = self._data.get(item)
File "C:\Python\Python36\lib\site-packages\pandas\core\internals.py", line 3590, in get
loc = self.items.get_loc(item)
File "C:\Python\Python36\lib\site-packages\pandas\core\indexes\base.py", line 2444, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5280)
File "pandas\_libs\index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5126)
File "pandas\_libs\hashtable_class_helper.pxi", line 1210, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20523)
File "pandas\_libs\hashtable_class_helper.pxi", line 1218, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20477)
KeyError: '交易日期'
|
|