一、软件及对应版本
Python 3.6.1 |Anaconda custom
Flask 0.12.2
Echarts 4.0
二、项目目录
Project directory.jpg
三、代码展示
server.py
from flask import Flask,render_template, url_for
import pymysql
import pandas as pd
app = Flask(__name__)
app.jinja_env.filters['zip'] = zip
def conn_db():
conn = pymysql.connect(host="your_host", user="your_username", password="your_password", db="your_database", charset="utf8")
return conn
def get_data(conn=conn_db(), n=10):
# Get the top10 products
sql = "select ProductMName, date_format(FeedbackDate, '%Y-%m') Month, count(FeedBack) Count from Feedbacks group by ProductMName, Month order by Count desc, Month asc"
df = pd.read_sql(sql, conn)
conn.close()
product_count = []
for index, value in enumerate(df["ProductMName"].unique()):
product_count.append([value, index+1])
product_count = dict(product_count)
df["Rank"] = df["ProductMName"].map(lambda x: product_count[x])
df = df[