为什么在烧瓶应用程序127.0.0.1中出现KeyError:0--[31 / Oct / 2019 00:01:07]“ POST / results HTTP / 1.1” 500-?

时间:2019-10-30 18:59:32

标签: python-3.x pandas dataframe flask

我正在制作一个Flask应用程序,在该应用程序中,我已通过.html页面从用户那里获取了输入,后来我将不同变量的值转换为字典,然后将其转换为熊猫的数据帧并存储在其值内部的变量中我想显示为0的索引,但它给出了错误,如何解决?

我无法识别错误及其原因。

用于预测价值并显示其价值的代码包括:

dic = {'MRP':MRP,'Fat':Fat,'Visibility':Visibility,'Weight':Weight,'Years':Years}

fdata_input = pd.DataFrame(dic,index=[0],columns=['MRP','Fat','Visibility','Weight','Years'])                           

price = rf.predict(fdata_input[0])

//我要显示存储在fdata_input的索引0中的值

这是我收到的错误消息:

http://127.0.0.1:5000/上运行(按CTRL + C退出)

127.0.0.1--[2019年10月31日00:00:58]“ GET / HTTP / 1.1” 200-

[2019-10-31 00:01:07,482]应用程序中出现错误:/结果[POST]上的异常

  

Traceback (most recent call last): File "C:\Users\HP\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2657, in get_loc return self._engine.get_loc(key) File "pandas/_libs/index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 0 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\HP\Anaconda3\lib\site-packages\flask\app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "C:\Users\HP\Anaconda3\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\HP\Anaconda3\lib\site-packages\flask\app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\HP\Anaconda3\lib\site-packages\flask\_compat.py", line 35, in reraise raise value File "C:\Users\HP\Anaconda3\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\HP\Anaconda3\lib\site-packages\flask\app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "<ipython-input-4-303728ed6a31>", line 51, in results predicted_stock_price = rf.predict(fdata_input[0]) File "C:\Users\HP\Anaconda3\lib\site-packages\pandas\core\frame.py", line 2927, in __getitem__ indexer = self.columns.get_loc(key) File "C:\Users\HP\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2659, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas/_libs/index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 0

127.0.0.1--[2019年10月31日00:01:07]“ POST /结果HTTP / 1.1” 500-

我希望显示fdata_input的索引0处的值。

0 个答案:

没有答案