In [ ]:
# bar chart for given grading component and given student name all blue except student in red
import pandas as pd
In [ ]:
df = pd.read_csv("grades.csv")
df
Out[ ]:
SNAME PROJS MT FINAL
0 DUMMY 60 20 20
1 DUMMY 620 95 160
2 Alice 578 64 126
3 Bob 620 84 123
4 Carol 578 42 133
5 Cyrus 620 65 120
6 David 620 76 152
7 Donald 620 83 148
8 Esther 620 75 160
9 George 496 48 70
10 Haslem 620 68 138
11 Henry 620 69 108
12 Howard 526 82 108
13 Joseph 620 70 146
14 Ken 617 70 25
15 Lohith 601 73 111
16 Manuel 620 73 148
17 Morgan 620 76 148
18 Muncie 620 67 113
19 Nathan 620 70 116
20 Norrie 593 68 0
21 Opal 620 75 142
22 Peter 620 79 148
23 Pim 610 65 148
24 Podesta 620 65 148
25 Pug 578 56 89
26 Rain 549 49 120
27 Raj 620 58 134
28 Raskin 600 66 0
29 Reefer 603 80 118
30 Right 620 78 134
31 Round 561 78 140
32 Ruskin 620 69 148
33 Sam 514 92 153
34 Singh 298 0 0
35 Solomon 600 89 134
36 Trent 620 67 143
37 Veronica 620 79 128
38 Walter 620 77 126
39 Wendy 620 80 148
40 Xavier 620 73 148
41 Zoe 586 68 140
In [ ]:
weights = df.iloc[0] 
maxpoints = df.iloc[1]
scores = df[2:]
scores.reset_index(inplace=True)
scores = scores.drop('index',axis=1)
scores["AVG"] = weights.loc["PROJS"]*scores['PROJS']/maxpoints.loc["PROJS"] + \
                    weights.loc["MT"]*scores['MT']/maxpoints.loc["MT"] + \
                    weights.loc["FINAL"]*scores['FINAL']/maxpoints.loc["FINAL"]
print(scores)
       SNAME  PROJS  MT  FINAL        AVG
0      Alice    578  64    126  85.159168
1        Bob    620  84    123  93.059211
2      Carol    578  42    133  81.402589
3      Cyrus    620  65    120  88.684211
4      David    620  76    152  95.000000
5     Donald    620  83    148  95.973684
6     Esther    620  75    160  95.789474
7     George    496  48     70  66.855263
8     Haslem    620  68    138  91.565789
9      Henry    620  69    108  88.026316
10    Howard    526  82    108  81.666384
11    Joseph    620  70    146  92.986842
12       Ken    617  70     25  77.571520
13    Lohith    601  73    111  87.404711
14    Manuel    620  73    148  93.868421
15    Morgan    620  76    148  94.500000
16    Muncie    620  67    113  88.230263
17    Nathan    620  70    116  89.236842
18    Norrie    593  68      0  71.702886
19      Opal    620  75    142  93.539474
20     Peter    620  79    148  95.131579
21       Pim    610  65    148  91.216469
22   Podesta    620  65    148  92.184211
23       Pug    578  56     89  78.849958
24      Rain    549  49    120  78.444822
25       Raj    620  58    134  88.960526
26    Raskin    600  66      0  71.959253
27    Reefer    603  80    118  89.946944
28     Right    620  78    134  93.171053
29     Round    561  78    140  88.211375
30    Ruskin    620  69    148  93.026316
31       Sam    514  92    153  88.235357
32     Singh    298   0      0  28.838710
33   Solomon    600  89    134  93.551358
34     Trent    620  67    143  91.980263
35  Veronica    620  79    128  92.631579
36    Walter    620  77    126  91.960526
37     Wendy    620  80    148  95.342105
38    Xavier    620  73    148  93.868421
39       Zoe    586  68    140  88.525467
In [ ]:
scores[["PROJS","MT","FINAL","AVG"]].mean()
Out[ ]:
PROJS    593.700000
MT        69.150000
FINAL    119.550000
AVG       86.956483
dtype: float64
In [ ]:
import plotly.express as px
import plotly.graph_objects as go
import numpy as np

sname = "Raj"
compname = "FINAL"

comp = scores[["SNAME",compname]].sort_values(by=compname,ascending=False)
colors = list(np.where(comp["SNAME"]==sname,'red','blue'))
comp['category'] = [str(i) for i in comp.index]  # values to cycle through for plotly to change colors

fig = px.bar(comp,x="SNAME",y=compname, color='category',color_discrete_sequence=colors)
fig.add_trace(go.Scatter(x=comp["SNAME"],
                         y=comp[compname],
                         text=comp[compname],
                         mode='text',
                         textposition='top center'))
fig.update_layout(showlegend=False)
fig.update_layout(
    font=dict(
        family="Arial, monospace",
        size=12
    )
)
fig.show()
In [ ]:
def plot_given_sname_compname(sname,compname):
    comp = scores[["SNAME",compname]].sort_values(by=compname,ascending=False)
    colors = list(np.where(comp["SNAME"]==sname,'red','blue'))
    comp['category'] = [str(i) for i in comp.index]  # values to cycle through for plotly to change colors

    fig = px.bar(comp,x="SNAME",y=compname, color='category',color_discrete_sequence=colors)
    fig.add_trace(go.Scatter(x=comp["SNAME"],
                             y=comp[compname],
                             text=comp[compname],
                             mode='text',
                             textposition='top center'))
    fig.update_layout(showlegend=False)
    fig.update_layout(
        font=dict(
            family="Arial, monospace",
            size=12
        )
    )
    fig.show()
In [ ]:
plot_given_sname_compname("Raj","MT")
In [ ]:
plot_given_sname_compname("Raj","FINAL")
In [ ]:
plot_given_sname_compname("Esther","MT")