[英]Pandas CSV Table to html Flask
我有這個 csv,我用 pandas 閱讀它,我想在 html 中將其顯示為表格。 我怎樣才能做到這一點? 我試圖將數據集解析為數據集,並在 html 中執行循環,例如數據集 print i 中的 for i。 但它不起作用。 有小費嗎?
這是 flask py:
from flask import Flask, render_template
import pandas as pd
import matplotlib.pyplot as plt
# from pylab import rcParams
import numpy as np
# import seaborn as sns
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
import torch
from torch import nn, optim
# from pandas.plotting import register_matplotlib_converters
from math import sqrt
from sklearn.metrics import mean_absolute_error
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
app = Flask(__name__)
@app.route('/')
def homepage():
return render_template('index.html')
@app.route('/preprocessing')
def about_page():
return render_template('preprocessing.html', data=dataset)
dataset = pd.read_csv('Data_Covid_Bandung.csv',index_col=[0],parse_dates = [0])
這是桌子
對於任何 dataframe,您都可以將其轉換為多種 output 格式:
df = pd.DataFrame(dict(x=[1,2,3], y=[2,3,4]))
df.to_html()
結果字符串:
'<table border="1" class="dataframe">\n <thead>\n <tr style="text-align: right;">\n <th></th>\n <th>x</th>\n <th>y</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>2</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>4</td>\n </tr>\n </tbody>\n</table>'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.