generated from Code-Institute-Org/gitpod-full-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
6-happiest-day-of-week.py
101 lines (92 loc) · 2.88 KB
/
6-happiest-day-of-week.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import justpy as jp
import pandas as pd
from datetime import datetime
from pytz import utc # Needed to support dtype=datetime64[ns, UTC] from Pandas and datetime.datetime comparison
from justpy import chartcomponents
# Load the Pandas DataFrame
data = pd.read_csv('assets/csv/reviews.csv', parse_dates=['Timestamp']) # Timestamp column is parsed as text otherwise
data['Weekday'] = data['Timestamp'].dt.strftime('%A')
data['Daynumber'] = data['Timestamp'].dt.strftime('%w')
weekday_average = data.groupby(['Weekday', 'Daynumber']).mean()
weekday_average = weekday_average.sort_values('Daynumber')
# Highcharts Spline Chart JS Code
# https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/spline-inverted
chart_def = """
{
chart: {
type: 'spline',
inverted: false
},
title: {
text: ''
},
subtitle: {
text: ''
},
xAxis: {
reversed: false,
title: {
enabled: true,
text: 'Day'
},
labels: {
format: '{value}'
},
accessibility: {
rangeDescription: 'Range: Monday to Friday.'
},
maxPadding: 0.05,
showLastLabel: true
},
yAxis: {
title: {
text: 'Rating'
},
labels: {
format: '{value}°'
},
accessibility: {
rangeDescription: 'Range: 0 to 5.'
},
lineWidth: 2
},
legend: {
enabled: false
},
tooltip: {
headerFormat: '<b>{series.name}</b><br/>',
pointFormat: '{point.x} : {point.y}'
},
plotOptions: {
spline: {
marker: {
enable: false
}
}
},
series: [{
name: 'Rating',
data: []
}]
}
"""
def app():
"""
Function to create a Quasar Page using the Vue.js framework from the supported components within the JustPy package.
Highcharts SVG Charting Library is used to create the data visualisation.
"""
webpage = jp.QuasarPage()
jp.QDiv(a=webpage, text="Analysis of Course Reviews", classes="text-h3 text-center q-pa-md")
jp.QDiv(a=webpage, text="These graphs represent course review analysis", classes="text-h5 text-center q-pa-md")
# JustPy converts string to Python Dictionary before displaying the content
hc = jp.HighCharts(a=webpage, options=chart_def)
"""
Access the hc dictionary keys using dot notation.
Pass the Pandas DataFrame index and column data as chart x & y values
"""
hc.options.title.text = 'Aggregated Average Ratings by Day of the Week'
hc.options.subtitle.text = 'Interactive chart using JustPy with HighCharts'
hc.options.xAxis.categories = list(weekday_average.index.get_level_values(0))
hc.options.series[0].data = list(weekday_average['Rating'])
return webpage
jp.justpy(app)