我已经写了我的代码,目的是在Web页面中显示表格。但是,到目前为止,我当前的结果来自控制台,但是我想从网页上查看。
下面是我尝试过的
app.layout = dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict("rows"),
)
@app.callback(
output=Output('my-table', 'table'),
)
def make_dash_table(df):
''' Return a dash definitio of an HTML table for a Pandas dataframe '''
metadata = pd.read_csv('ratings.csv', low_memory=False)
# Calculate C
C = metadata['rating_average'].mean()
# Calculate the minimum number of votes required to be in the chart, m
m = metadata['rating_count'].quantile(0.90)
# Filter out all qualified movies into a new DataFrame
q_movies = metadata.copy().loc[metadata['rating_count'] >= m]
def weighted_rating(x, m=m, C=C):
v = x['rating_count']
R = x['rating_average']
# Calculation based on the IMDB formula
return (v / (v + m) * R) + (m / (m + v) * C)
# Define a new feature 'score' and calculate its value with `weighted_rating()`
q_movies['score'] = q_movies.apply(weighted_rating, axis=1)
# Sort movies based on score calculated above
q_movies = q_movies.sort_values('score', ascending=False)
# Print the top 15 movies
eta= q_movies[['Product_Name', 'rating_count', 'rating_average', 'score']].head(15)
return eta
if __name__ == '__main__':
app.run_server(debug=True, threaded=True)
代码应返回网页中的表格