In [1]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 } else {
 $('div.input').show();
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
Out[1]:
In [2]:
# Import libraries
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import squarify    
import plotly.express as px
import seaborn as sns
In [3]:
# Read in data
df = pd.read_excel("scottish_universities_subject_enrollments.xlsx", header=16)
In [4]:
# Drop UKPRN
df.drop(["UKPRN"], axis=1, inplace=True)
In [5]:
# Drop "Total" row
df.drop([18], inplace=True)

Summary analysis of Scottish university UG enrollments in 2019/2020


Breakdown of UG student enrollment at Scottish universities

In [6]:
df
Out[6]:
HE provider Abbreviation 01 Medicine and dentistry 02 Subjects allied to medicine 03 Biological and sport sciences 04 Psychology 05 Veterinary sciences 06 Agriculture, food and related studies 07 Physical sciences 08 General and others in sciences ... 15 Social sciences 16 Law 17 Business and management 18 Communications and media 19 Language and area studies 20 Historical, philosophical and religious studies 21 Creative arts and design 22 Education and teaching 23 Combined and general studies Total
0 Abertay University AU 0 260 310 400 0 160 75 0 ... 380 205 435 0 0 0 0 0 0 3665
1 Edinburgh Napier University ENU 0 1880 520 250 180 30 0 0 ... 470 265 1905 255 365 0 810 0 30 9365
2 Glasgow Caledonian University GCU 90 3990 105 445 0 70 170 0 ... 785 285 2675 325 40 0 315 0 0 12185
3 Glasgow School of Art GSoA 0 0 0 0 0 0 0 0 ... 15 0 0 0 5 225 1010 0 0 1605
4 Heriot-Watt University HWU 0 0 330 300 0 60 440 5 ... 265 25 1600 0 290 0 630 0 0 7605
5 Queen Margaret University, Edinburgh QMU 0 1165 60 235 0 0 0 0 ... 175 0 590 385 0 0 360 125 0 3105
6 Robert Gordon University RGU 0 2325 155 0 0 0 125 0 ... 560 380 1715 465 0 0 680 0 0 8080
7 Royal Conservatoire of Scotland RCS 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 805 100 0 900
8 SRUC SRUC 0 0 0 0 60 900 0 50 ... 0 0 40 0 0 0 0 0 0 1150
9 The University of Aberdeen UoA 1070 370 880 685 0 5 375 0 ... 1200 875 710 0 600 565 210 505 5 9510
10 The University of Dundee UoD 1225 2335 300 435 0 0 135 0 ... 590 615 615 35 315 350 1180 415 10 10255
11 The University of Edinburgh UoE 1145 580 1605 620 745 75 1530 10 ... 2595 895 1385 0 2365 2340 1200 520 60 22395
12 The University of Glasgow UoG 1925 840 1295 545 730 45 1045 0 ... 1800 865 920 35 1675 1520 560 935 0 18555
13 The University of St Andrews UoStA 575 75 460 475 0 0 835 35 ... 1350 0 360 95 1030 1110 0 0 100 7790
14 The University of Stirling UoS 0 1045 985 665 0 45 5 20 ... 1070 390 1145 440 520 490 70 420 0 8100
15 The University of Strathclyde UoSc 0 1015 430 420 0 0 915 15 ... 940 895 2040 130 615 325 135 810 95 13960
16 The University of the West of Scotland UoWoS 0 2855 1150 515 0 0 250 0 ... 1750 190 2455 285 0 0 540 325 0 11900
17 University of the Highlands and Islands UoH&I 40 570 315 105 0 135 120 75 ... 1030 0 925 40 155 305 755 65 0 5510

18 rows × 27 columns

In [7]:
# Wide to long data
melted_df = pd.melt(df, id_vars=['HE provider', 'Abbreviation'], value_vars=['01 Medicine and dentistry',
       '02 Subjects allied to medicine', '03 Biological and sport sciences',
       '04 Psychology', '05 Veterinary sciences',
       '06 Agriculture, food and related studies', '07 Physical sciences',
       '08 General and others in sciences', '09 Mathematical sciences',
       '10 Engineering and technology', '11 Computing',
       '12 Geographical and environmental studies (natural sciences)',
       '13 Architecture, building and planning',
       '12 Geographical and environmental studies (social sciences)',
       '14 Humanities and liberal arts (non-specific)', '15 Social sciences',
       '16 Law', '17 Business and management', '18 Communications and media',
       '19 Language and area studies',
       '20 Historical, philosophical and religious studies',
       '21 Creative arts and design', '22 Education and teaching',
       '23 Combined and general studies'],
        var_name='Subject', value_name='Number of students')

Breakdown by university then by subject

The plot below orders the university and subsequently the subject area by number of student enrollments. Also, the darker the shade of blue and the larger the cube, the greater the number of students.

From the plot, we can see that The University of Edinburgh has the largest number of student enrollments (22,390) and the Royal Conservatoire of Scotland has the smallest number of student enrollments (905).

We can also see that "02 Subjects allied to medicine" at Glasgow Caledonian University has the greatest number of student enrollments out of the subject areas (3990), followed by "10 Engineering and technology" at The University of Strathclyde (3725).

Student enrollments in Computing subjects contributes to approx. 35% of Abertay University's total enrollments (1295/3655). While this is not the highest number of Computing student enrollments of a university (Edinburgh Napier University has 1440, approx. 15% of student enrollments).

In [8]:
# Treemap doesn't like zeros - get rid of them
melted_df = melted_df[melted_df['Number of students']!=0]

# Plot treemap
fig = px.treemap(melted_df, path=['HE provider', 'Subject'], values='Number of students', color='Number of students', 
                color_continuous_scale='PuBu', width=1200, height=600)

fig.show()