python 3.5.1中的Pandas错误

时间:2017-04-02 11:09:35

标签: python-3.x pandas quandl

我正在使用python 3.5.1,以下显示数据

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

我正在做以下

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())

但显示以下错误

追踪(最近一次通话):   get_loc中的文件“C:\ Users \ jayram \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ pandas \ _dedex.py”,第2134行     return self._engine.get_loc(key)   在pandas.index.IndexEngine.get_loc中文件“pandas \ index.pyx”,第132行(pandas \ index.c:4433)   在pandas.index.IndexEngine.get_loc中文件“pandas \ index.pyx”,第154行(pandas \ index.c:4279)   在pandas.hashtable.PyObjectHashTable.get_item中文件“pandas \ src \ hashtable_class_helper.pxi”,第732行(pandas \ hashtable.c:13742)   在pandas.hashtable.PyObjectHashTable.get_item中文件“pandas \ src \ hashtable_class_helper.pxi”,第740行(pandas \ hashtable.c:13696) KeyError:'调整。开'

在处理上述异常期间,发生了另一个异常:

追踪(最近一次通话):   文件“C:/ Users / jayram / Desktop / python / ok2”,第7行,in     df ['PCT_change'] =(df ['Adj.Close'] - df ['Adj.Open'])/ df ['Adj。打开“] * 100.0   文件“C:\ Users \ jayram \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ pandas \ core \ frame.py”,第2059行, getitem     return self._getitem_column(key)   _getitem_column中的文件“C:\ Users \ jayram \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ pandas \ core \ frame.py”,第2066行     return self._get_item_cache(key)   在_get_item_cache中输入文件“C:\ Users \ jayram \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ pandas \ core \ generic.py”,第1386行     values = self._data.get(item)   文件“C:\ Users \ jayram \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ pandas \ core \ internals.py”,第3543行,获取     loc = self.items.get_loc(item)   get_loc中的文件“C:\ Users \ jayram \ AppData \ Local \ Programs \ Python \ Python35 \ lib \ site-packages \ pandas \ _dex \ base.py”,第2136行     return self._engine.get_loc(self._maybe_cast_indexer(key))   在pandas.index.IndexEngine.get_loc中文件“pandas \ index.pyx”,第132行(pandas \ index.c:4433)   在pandas.index.IndexEngine.get_loc中文件“pandas \ index.pyx”,第154行(pandas \ index.c:4279)   在pandas.hashtable.PyObjectHashTable.get_item中文件“pandas \ src \ hashtable_class_helper.pxi”,第732行(pandas \ hashtable.c:13742)   在pandas.hashtable.PyObjectHashTable.get_item中文件“pandas \ src \ hashtable_class_helper.pxi”,第740行(pandas \ hashtable.c:13696) KeyError:'调整。开'

使用退出代码1完成处理

如何解决上述错误

1 个答案:

答案 0 :(得分:1)

变化

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

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