I am sending an ajax GET request to a flask server (http://localhost:5000/req/?q=139,2,10,60,5,1462,7,5,6,9,17,78) in order to retrieve some values and assign them to a Dataframe. Doing it manually, it works fine:
df = pd.DataFrame(data=[[139,2,10,60,5,1462,7,5,6,9,17,78]],columns=['col1','col2','col3','col4','col5','col6','col7','col8','col9','col10','col11','col12'])
but i need the numbers to come from request.args via ajax and then be based in the Dataframe as an array.
@app.route('/req/', methods=['GET'])
def foo():
args = dict(request.args.to_dict())
t = request.args["q"]
return getResults(t), 200
And the getResults() would be something like:
def getResults(name):
df = pd.DataFrame(data=[[name]], columns=['col1','col2','col3','col4','col5','col6','col7','col8','col9','col10','col11','col12'])
""""
but of course this doesn't work. Gives an error: ValueError: 12 columns passed, passed data had 1 columns
How can i do this ? I've tried splitting the string, try to convert to an array..nothing worked.
args = dict(request.args.to_dict())? request.args is already a nice dict