0

I'm looking to build a basic website using Flask to display predictions from a python machine learning project. I have the following file structure:

project/
    static/
        style.css
        script.js
    templates/
        index.html
    server.py

And I'm looking to pass the predictions from my server.py into my index.html

The predictions are stored in a Pandas DataFrame in the following format:

      P1     P2
0     60     40
1     26     74

I've managed to pass this data into my index.html with the following code in my server.py file:

a = df['P1'][0]
b = df['P2'[0]
c = df['P1'][1]
d = df['P2'[1]

@app.route('/')
def pass_data():
    return render_template('index.html', a=a, b=b, c=c, d=d)

In reality I have far more predictions I wish to display in my index.html. So my question is, is there a better, more efficient way to pass data from my DataFrame into my index.html, as opposed to defining each one individually and passing them in the return command of the pass_data() function.

Appreciate any recommendations, cheers!

1 Answer 1

2

How about passing the entire dataframe?

In the python file

return render_template('index.html', df=df)

Inside body tag inside index.html

{{ df.to_html() | safe }}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.