You'll want to first melt the Chemistry, Physics, Math columns down into two columns: one identifer column and another column with the corresponding values.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
## recreate your DataFrame
df = pd.DataFrame({
'Name':list("QWERTYUI"),
'Student ID': list(range(12001,12009)),
'Race':list('ABCDABCD'),
'Chemistry': [59,54,42,66,60,78,64,82],
'Physics': [90,42,88,48,80,73,43,69],
'Math': [45,85,54,64,72,64,67,70]
})
df_melted = pd.melt(df, id_vars=['Name','Student ID','Race'], value_vars=['Chemistry','Physics','Math'])
Here you can see the difference between how the two DataFrames are structured:
>>> df
Name Student ID Race Chemistry Physics Math
0 Q 12001 A 59 90 45
1 W 12002 B 54 42 85
2 E 12003 C 42 88 54
3 R 12004 D 66 48 64
4 T 12005 A 60 80 72
5 Y 12006 B 78 73 64
6 U 12007 C 64 43 67
7 I 12008 D 82 69 70
>>> df_melted
Name Student ID Race variable value
0 Q 12001 A Chemistry 59
1 W 12002 B Chemistry 54
2 E 12003 C Chemistry 42
3 R 12004 D Chemistry 66
4 T 12005 A Chemistry 60
5 Y 12006 B Chemistry 78
6 U 12007 C Chemistry 64
7 I 12008 D Chemistry 82
8 Q 12001 A Physics 90
9 W 12002 B Physics 42
10 E 12003 C Physics 88
11 R 12004 D Physics 48
12 T 12005 A Physics 80
13 Y 12006 B Physics 73
14 U 12007 C Physics 43
15 I 12008 D Physics 69
16 Q 12001 A Math 45
17 W 12002 B Math 85
18 E 12003 C Math 54
19 R 12004 D Math 64
20 T 12005 A Math 72
21 Y 12006 B Math 64
22 U 12007 C Math 67
23 I 12008 D Math 70
Then you can call sns.barplot with the following arguments:
ax = sns.barplot(x="Race", y="value", hue="variable", data=df_melted)
plt.show()
