Python ValueError:传递值的形状是 (1, 6),索引意味着 (6, 6)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50185926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ValueError: Shape of passed values is (1, 6), indices imply (6, 6)
提问by Sbk3824
I am passing a list from flask function to another function, and getting this value error.
我正在将一个列表从 Flask 函数传递给另一个函数,并得到这个值错误。
My code at sending end:
我在发送端的代码:
@app.route('/process', methods=['POST'])
def process():
name = request.form['name']
comment = request.form['comment']
wickets = request.form['wickets']
ga = request.form['ga']
ppballs = request.form['ppballs']
overs = request.form['overs']
score = [name,comment,wickets,ga,ppballs,overs]
results = []
results = eval_score(score)
print results
Receiver end :
接收端:
def ml_model(data):
col = pd.DataFrame(data,columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
predicted = predictor(col)
Trace of Error:
错误跟踪:
...
line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/sbk/guestbook/guestbook.py", line 26, in process
results = eval_score(score)
File "/Users/sbk/guestbook/eval_score.py", line 6, in eval_score
col = pd.DataFrame(data,columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
File "/Users/sbk/anaconda2/lib/python2.7/site- packages/pandas/core/frame.py", line 385, in __init__
copy=copy)
File "/Users/sbk/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 533, in _init_ndarray
return create_block_manager_from_blocks([values], [columns, index])
File "/Users/sbk/anaconda2/lib/python2.7/site-packages/pandas/core/internals.py", line 4631, in create_block_manager_from_blocks
construction_error(tot_items, blocks[0].shape[1:], axes, e)
File "/Users/sbk/anaconda2/lib/python2.7/site-packages/pandas/core/internals.py", line 4608, in construction_error
Open an interactive python shell in this framepassed, implied))
Please let me know where I am going wrong.
请让我知道我哪里出错了。
回答by rafaelc
Simply change
简单地改变
col = pd.DataFrame(data, columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
for
为了
col = pd.DataFrame([data], columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
You want [data]
for pandas
to understand they're rows.
你想[data]
为pandas
了解他们的行。
Simple illustration:
简单说明:
a = [1, 2, 3]
>>> pd.DataFrame(a)
0
0 1
1 2
2 3
>>> pd.DataFrame([a])
0 1 2
0 1 2 3
回答by Candice Withrow
I was having similar issues with making a dataframe from regressor coefficients (regressor.coeff_), and brackets gave another error asking for 2-d input. If you get this error, try appending the input array with [0] so it pulls the values out. ex: data[0]
我在从回归系数(regressor.coeff_)制作数据帧时遇到了类似的问题,括号给出了另一个要求二维输入的错误。如果您收到此错误,请尝试使用 [0] 附加输入数组,以便将值拉出。例如:数据[0]