【问题标题】:How do i fix errors in pandas lib while working in python?在 python 中工作时,如何修复 pandas lib 中的错误?
【发布时间】:2019-07-04 06:48:24
【问题描述】:

我正在尝试这个 .. 使用 pandas 从 quandl 获取数据集来整理必要的数据。当这出现在执行时。

import pandas as pd
import quandl
df = quandl.get('WIKI/GOOGL')
print(df.head())
df = df[['Adj. Open','Adj. High','Adj. Low','Adj. Close','Adj. Volume']]
print(df.head())
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']]

所以我得到了一条错误消息

更新:

我用正确的大写更新了我的代码 现在它得到了这个错误

Traceback(最近一次调用最后一次): 文件“D:\Program Files\Python37\lib\site-packages\pandas\core\indexes\base.py”,第 2656 行,在 get_loc 返回 self._engine.get_loc(key) 文件“pandas_libs\index.pyx”,第 108 行,在 pandas._libs.index.IndexEngine.get_loc 文件“pandas_libs\index.pyx”,第 132 行,在 pandas._libs.index.IndexEngine.get_loc 文件“pandas_libs\hashtable_class_helper.pxi”,第 1601 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item 文件“pandas_libs\hashtable_class_helper.pxi”,第 1608 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Adj .Close'

在处理上述异常的过程中,又发生了一个异常:

Traceback(最近一次调用最后一次): 文件“sentdex2.py”,第 8 行,在 df['PCT_change'] = (df['Adj.Close']-df['Adj. Open'])/df['Adj.Close']打开'] *100.0 getitem 中的文件“D:\Program Files\Python37\lib\site-packages\pandas\core\frame.py”,第 2927 行 索引器 = self.columns.get_loc(key) 文件“D:\Program Files\Python37\lib\site-packages\pandas\core\indexes\base.py”,第 2658 行,在 get_loc 返回 self._engine.get_loc(self._maybe_cast_indexer(key)) 文件“pandas_libs\index.pyx”,第 108 行,在 pandas._libs.index.IndexEngine.get_loc 文件“pandas_libs\index.pyx”,第 132 行,在 pandas._libs.index.IndexEngine.get_loc 文件“pandas_libs\hashtable_class_helper.pxi”,第 1601 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item 文件“pandas_libs\hashtable_class_helper.pxi”,第 1608 行,在 pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Adj .Close'

【问题讨论】:

  • 请不要将错误发布为图片

标签: python-3.x


【解决方案1】:

Adj. close 替换为Adj. Close(注意大写C

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多