Last active
May 21, 2021 19:23
-
-
Save mkhorasani/1669d29f2de203ab1213685205dd2ea1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = pd.read_excel('C:/Users/.../Desktop/Exam_results.xlsx') | |
exam_averages = [int(df['Exam 1'].mean()), int(df['Exam 2'].mean()), | |
int(df['Exam 3'].mean()), int(df['Exam 4'].mean())] | |
exams = ['Exam 1', 'Exam 2', 'Exam 3', 'Exam 4'] | |
for i in range(0,len(df)): | |
exam_results = [df.loc[i]['Exam 1'], df.loc[i]['Exam 2'], df.loc[i]['Exam 3'], df.loc[i]['Exam 4']] | |
#Line chart | |
fig = go.Figure() | |
fig.add_trace(go.Scatter( | |
name=('%s' % (df.loc[i]['Name'] + ' ' + df.loc[i]['Surname'])) ,x=exams, y=exam_results, | |
text=exam_results, | |
)) | |
fig.add_trace(go.Scatter( | |
name='Average',x=exams, y=exam_averages, | |
text=exam_averages, | |
)) | |
fig.update_layout( | |
title_text='Average Exam Scores', | |
xaxis_title_text='Exam', | |
yaxis_title_text='Score', | |
) | |
fig.update_layout(height=700, showlegend=True) | |
fig.write_image('C:/Users/.../Desktop/line_chart.png') | |
#Bar chart | |
fig_1 = go.Figure(data=[ | |
go.Bar(name='%s' % (df.loc[i]['Name'] + ' ' + df.loc[i]['Surname']), | |
x=exams, y=exam_results,text=exam_results,textposition='auto',), | |
go.Bar(name='Average', x=exams, y=exam_averages,text=exam_averages, | |
textposition='auto') | |
]) | |
fig_1.update_layout( | |
title_text='Average Exam Scores', | |
xaxis_title_text='Exam', | |
yaxis_title_text='Score', | |
) | |
fig_1.update_layout(height=700, showlegend=True) | |
fig_1.write_image('C:/Users/.../Desktop/bar_chart.png') | |
#Histogram plot | |
fig_2 = go.Figure() | |
fig_2.add_trace(go.Histogram(name='Exam 1',x=df['Exam 1'])) | |
fig_2.add_trace(go.Histogram(name='Exam 2',x=df['Exam 2'])) | |
fig_2.add_trace(go.Histogram(name='Exam 3',x=df['Exam 3'])) | |
fig_2.add_trace(go.Histogram(name='Exam 4',x=df['Exam 4'])) | |
fig_2.update_layout( | |
title_text='Histogram of Exam Scores', | |
xaxis_title_text='Score', | |
yaxis_title_text='Count', | |
) | |
fig_2.update_layout(height=700, showlegend=True) | |
fig_2.write_image('C:/Users/.../Desktop/histogram.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment