How to recalculate data from table in flask/python?

Solution
from flask import Flask, request, render_template, session, redirect, jsonify
import pandas as pd
import numpy as np

app = Flask(__name__)

df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
                   'B': [5, 6, 7, 8, 9],
                   'C': [6, 9, 1, 2, 5]})

sum_df = df.to_numpy().sum()

@app.route('/')
def index():
    data = [df.columns.values.tolist()] + df.values.tolist()
    return render_template('index.html', data=data, sum_df=sum_df)


@app.route('/submit-data', methods=["POST"])
def submitData():
    data = request.get_json()
    global df
    global sum_df
    df = pd.DataFrame(data)
    df = df.apply(pd.to_numeric)
    sum_df = df.to_numpy().sum()
    return jsonify({"status": "OK"})


if __name__ == '__main__':
    app.run(debug=True, host='127.0.0.1', port="5000")



Test
     
    
    
    

Table

{% for col in data[0] %} {% endfor %} {% for row in range(1, data|length) %} {% for i in data[row] %} {% endfor %} {% endfor %}
{{col}}
{{row}}
{{sum_df}}