如何在烧瓶中返回dtype(object)

时间:2019-11-01 14:48:22

标签: python numpy flask

我正在尝试构建FLASK应用程序。在一种途径中,我希望浏览器打印使用numpy的函数的输出。但是,当代码运行时,会出现如下错误。

我有没有装饰器的功能。

def get_similar_places(userID):
    from sqlalchemy import create_engine
    import pymysql
    import pandas as pd
    db_connection_str = 'mysql+pymysql://root:VC@travel.c5dq5zer.us-east-1.rds.amazonaws.com/traveem'
    db_connection = create_engine(db_connection_str)
    df = pd.read_sql("select * from MatrixData where UserID = "+str(userID), con=db_connection)
    places = list(df.columns[1:])
    vector = df.iloc[0][1:]
    visited_places = [places[i] for i in range(len(places)) if vector[i] == 1]
    df = pd.read_sql('SELECT * FROM Similarity', con=db_connection)
    df.index = df.columns
    score = df.dot(vector).div(df.sum(axis=1))
    score = score.nlargest(10+len(visited_places))
    score = score.drop(visited_places)
    return [score.index, visited_places]

然后,我这样调用此函数:

@app.route('/cfoutput')
def collaborative_filtering():
    # reco = get_similar_places(userID = 1)
    # print(reco)
    #print(reco[1])
    return get_similar_places(userID = 1)

我希望输出是

Index(['kunti betta (near srirangapatna)', 'kudremukh (near sringeri)',
       'kukke sumbrahmanya temple (near mangalore)',
       'unchalli falls (near jog falls)', 'madhugiri (near bangalore)',
       'horanadu annapoorneshwari temple (near sringeri)',
       'jamalabad fort (near mangalore)', 'hemavathi dam (near sakleshpur)',
       'agni gudda hill / agani peak (near sakleshpur)', 'srirangapatna'],
      dtype='object')
['bangalore', 'harangi dam (near coorg)', 'dandeli']

但是,在浏览器中,我得到的错误是

TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a list.

我尝试使用Respone,make_response,作为json发送。没有选择的工作。任何帮助,将不胜感激。预先感谢。

0 个答案:

没有答案