По какой-то причине следующий код из учебника youtube дает трассировку из-за прокомментированной строки. Он и другие успешно запустил его в Python 3.Traceback с использованием столбцов в pandas
import Quandl
import pandas as pd
import math
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. Low'])/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']]
forecast_col = 'Adju. Close'
df.fillna(-99999, inplace=True)
forecast_out = int(math.ceil(0.01*len(df)))
df['label'] = df[forecast_col].shift(-forecast_out) #moves columns out 10% into future
df.dropna(inplace=True)
print(df.head())
Это дает:
Traceback (most recent call last):
File "C:\Users\student\Anaconda2\envs\py35\lib\site-packages\pandas\indexes\ba
se.py", line 1945, in get_loc
return self._engine.get_loc(key)
File "pandas\index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas
\index.c:4154)
File "pandas\index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas
\index.c:4018)
File "pandas\hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.g
et_item (pandas\hashtable.c:12368)
File "pandas\hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.g
et_item (pandas\hashtable.c:12322)
KeyError: 'Adju. Close'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\student\Desktop\Coursea\MachineLearning\Sentdex\2.py", line 17,
in <module>
df['label'] = df[forecast_col].shift(-forecast_out) #moves columns out 10% i
nto future
File "C:\Users\student\Anaconda2\envs\py35\lib\site-packages\pandas\core\frame
.py", line 1997, in __getitem__
return self._getitem_column(key)
File "C:\Users\student\Anaconda2\envs\py35\lib\site-packages\pandas\core\frame
.py", line 2004, in _getitem_column
return self._get_item_cache(key)
File "C:\Users\student\Anaconda2\envs\py35\lib\site-packages\pandas\core\gener
ic.py", line 1350, in _get_item_cache
values = self._data.get(item)
File "C:\Users\student\Anaconda2\envs\py35\lib\site-packages\pandas\core\inter
nals.py", line 3290, in get
loc = self.items.get_loc(item)
File "C:\Users\student\Anaconda2\envs\py35\lib\site-packages\pandas\indexes\ba
se.py", line 1947, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas
\index.c:4154)
File "pandas\index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas
\index.c:4018)
File "pandas\hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.g
et_item (pandas\hashtable.c:12368)
File "pandas\hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.g
et_item (pandas\hashtable.c:12322)
KeyError: 'Adju. Close'
В настоящее время я четыре питона установки. Две среды в анаконде, которые все функционируют хорошо, и две «нормальные» установки python, 2.7 и 3.5. Я попытался установить pandas
несколько раз в случае, если он был поврежден, но ничего не сделал.
Что смутило меня в этой операции, если мы переместили Adj. Закройте колонку до 10 дней в будущем (я думаю, что просто повторяю значения 1-10 дней на день 11-20), у нас нет значений для «HL_PCT», «PCT_change», «Adj. Объем »в течение 10 дней в будущем. Если это так, то как 'X_train, X_test, y_train, y_test = cross_validation.train_test_split (X, y, test_size = 0.2) ' собираются предоставить соответствующие значения ''HL_PCT', 'PCT_change', 'Adj. Volume'' для 'label' в течение 10 дней в будущем? где X и y - '' 'X = np.array (df.drop (['label'], 1)) y = np.array (df ['label'])' '' –