I am creating a Dataframe by taking input file from user on a website and processing it.After that I want the user to download the final result in a csv file.For that a Dataframe is required from previous function.
I have tried passing the dataframe but it is giving me error as it is defined in another function.
My code is
from flask import Flask, render_template, request, redirect
from werkzeug import secure_filename
app = Flask(__name__)
@app.route('/uploader', methods = ['GET','POST'])
def upload():
new=nrecs[['UserID','ProductID','Rating']]
new['Recommendations'] = list(zip(new.ProductID, new.Rating))
res=new[['UserID','Recommendations']]
res_new=res['Recommendations'].groupby([res.UserID]).apply(list).reset_index()
pd.options.display.max_colwidth = 500
return render_template('simple.html', tables=[res_new.to_html(classes='data')], titles='')
@app.route('/download-csv', methods = ['GET'])
def download():
return res_new.to_csv('Recommendations.csv')
This is a small snipet of my code not the full code.
When a user will click on download recommendations button it should download the csv file.
Is there any other way around it can be done.