KeyError: range(1994, 2014)

菜鸟的AI之路 2017-12-05 04:07:18
#-*- coding: utf-8 -*-
import numpy as np
import pandas as pd
from GM11 import GM11 #引入自己编写的灰色预测函数

inputfile = '../data/data1.csv' #输入的数据文件
outputfile = '../tmp/data1_GM11.xls' #灰色预测后保存的路径
modelfile = '../tmp/net.model'
data = pd.read_csv(inputfile) #读取数据
data.index = range(1994, 2014)

data.loc[2014] = None
data.loc[2015] = None
l = ['x1', 'x2', 'x3', 'x4', 'x5', 'x7']
for i in l:
f = GM11(data[i][range(1994, 2014)].as_matrix())[0]
data[i][2014] = f(len(data)-1) #2014年预测结果
data[i][2015] = f(len(data)) #2015年预测结果
data[i] = data[i].round(2) #保留两位小数

data[l+['y']].to_excel(outputfile) #结果输出
运行过程中出现报错,报错Keyerror:range()错误,怎么回事呀?
...全文
1124 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
安然失笑、 2019-05-17
  • 打赏
  • 举报
回复
f = GM11(data[i][:-2].as_matrix())[0]
爱跑步的george 2018-11-09
  • 打赏
  • 举报
回复
f = GM11(data[i][:-2].as_matrix())[0]
ftd_lyh 2018-01-08
  • 打赏
  • 举报
回复
请问你解决了吗?
菜鸟的AI之路 2017-12-06
  • 打赏
  • 举报
回复
请问,需要怎么修改呀?
黑泡泡选手 2017-12-05
  • 打赏
  • 举报
回复

f = GM11(data[i][range(1994, 2014)].as_matrix())[0]
检查这行代码,range返回的是一个列表,怎能用为key???

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧