ValueError: Shape of passed values is (1, 6), indices imply (6, 6)
ValueError: Shape of passed values is (1, 6), indices imply (6, 6)
我正在将一个列表从 flask 函数传递到另一个函数,并得到这个值错误。
发送端我的代码:
@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
接收端:
def ml_model(data):
col = pd.DataFrame(data,columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
predicted = predictor(col)
错误痕迹:
...
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))
请让我知道哪里出错了。
简单改变
col = pd.DataFrame(data, columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
为
col = pd.DataFrame([data], columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
您希望 [data]
和 pandas
了解它们是行。
简单说明:
a = [1, 2, 3]
>>> pd.DataFrame(a)
0
0 1
1 2
2 3
>>> pd.DataFrame([a])
0 1 2
0 1 2 3
我在从回归系数 (regressor.coeff_) 制作数据帧时遇到了类似的问题,括号给出了另一个要求二维输入的错误。如果出现此错误,请尝试在输入数组后附加 [0],以便提取值。
前任:
数据[0]
我遇到了与消息类似的错误
Shape of passed values is (68, 1783), indices imply (68, 68) in dataframe
并且根据我的猜测,我输入了数据的 ndarray 转置并解决了问题
更改自
Features_Dataframe = pd.DataFrame(data=Features, columns=Feature_Labels) # here Features ndarray is 68*1783
到
Features_Dataframe = pd.DataFrame(data=Features.transpose(), columns=Feature_Labels) # Now Features array became 1783*68 i.e., 1783 rows and 68 columns
改变这个:
pd.DataFrame(regr.coef_, df_coeficientes.columns, 列=['Coeffecient'])
对此:
pd.DataFrame(regr.coef_[0], df_coeficientes.columns, 列=['Coeffecient'])
我正在将一个列表从 flask 函数传递到另一个函数,并得到这个值错误。
发送端我的代码:
@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
接收端:
def ml_model(data):
col = pd.DataFrame(data,columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
predicted = predictor(col)
错误痕迹:
...
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))
请让我知道哪里出错了。
简单改变
col = pd.DataFrame(data, columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
为
col = pd.DataFrame([data], columns=['runs','balls', 'wickets', 'ground_average', 'pp_balls_left', 'total_overs'])
您希望 [data]
和 pandas
了解它们是行。
简单说明:
a = [1, 2, 3]
>>> pd.DataFrame(a)
0
0 1
1 2
2 3
>>> pd.DataFrame([a])
0 1 2
0 1 2 3
我在从回归系数 (regressor.coeff_) 制作数据帧时遇到了类似的问题,括号给出了另一个要求二维输入的错误。如果出现此错误,请尝试在输入数组后附加 [0],以便提取值。 前任: 数据[0]
我遇到了与消息类似的错误
Shape of passed values is (68, 1783), indices imply (68, 68) in dataframe
并且根据我的猜测,我输入了数据的 ndarray 转置并解决了问题
更改自
Features_Dataframe = pd.DataFrame(data=Features, columns=Feature_Labels) # here Features ndarray is 68*1783
到
Features_Dataframe = pd.DataFrame(data=Features.transpose(), columns=Feature_Labels) # Now Features array became 1783*68 i.e., 1783 rows and 68 columns
改变这个:
pd.DataFrame(regr.coef_, df_coeficientes.columns, 列=['Coeffecient'])
对此:
pd.DataFrame(regr.coef_[0], df_coeficientes.columns, 列=['Coeffecient'])