In [11]:
# %sh

# wget https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/recent-grads.csv

In [12]:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline

recent_grads = pd.read_csv("recent-grads.csv")
recent_grads.head(3)


Out[12]:
Rank Major_code Major Major_category Total Sample_size Men Women ShareWomen Employed ... Part_time Full_time_year_round Unemployed Unemployment_rate Median P25th P75th College_jobs Non_college_jobs Low_wage_jobs
0 1 2419 PETROLEUM ENGINEERING Engineering 2339 36 2057 282 0.120564 1976 ... 270 1207 37 0.018381 110000 95000 125000 1534 364 193
1 2 2416 MINING AND MINERAL ENGINEERING Engineering 756 7 679 77 0.101852 640 ... 170 388 85 0.117241 75000 55000 90000 350 257 50
2 3 2415 METALLURGICAL ENGINEERING Engineering 856 3 725 131 0.153037 648 ... 133 340 16 0.024096 73000 50000 105000 456 176 0

3 rows × 21 columns


In [13]:
recent_grads.tail(3)


Out[13]:
Rank Major_code Major Major_category Total Sample_size Men Women ShareWomen Employed ... Part_time Full_time_year_round Unemployed Unemployment_rate Median P25th P75th College_jobs Non_college_jobs Low_wage_jobs
170 171 5202 CLINICAL PSYCHOLOGY Psychology & Social Work 2838 13 568 2270 0.799859 2101 ... 648 1293 368 0.149048 25000 25000 40000 986 870 622
171 172 5203 COUNSELING PSYCHOLOGY Psychology & Social Work 4626 21 931 3695 0.798746 3777 ... 965 2738 214 0.053621 23400 19200 26000 2403 1245 308
172 173 3501 LIBRARY SCIENCE Education 1098 2 134 964 0.877960 742 ... 237 410 87 0.104946 22000 20000 22000 288 338 192

3 rows × 21 columns


In [14]:
recent_grads.describe()


Out[14]:
Rank Major_code Total Sample_size Men Women ShareWomen Employed Full_time Part_time Full_time_year_round Unemployed Unemployment_rate Median P25th P75th College_jobs Non_college_jobs Low_wage_jobs
count 173.000000 173.000000 173.000000 173.000000 173.000000 173.000000 173.000000 173.000000 173.000000 173.000000 173.000000 173.000000 172.000000 173.000000 173.000000 173.000000 173.000000 173.000000 173.000000
mean 87.000000 3879.815029 39167.716763 356.080925 16637.358382 22530.358382 0.522550 31192.763006 26029.306358 8832.398844 19694.427746 2416.329480 0.068587 40151.445087 29501.445087 51494.219653 12322.635838 13284.497110 3859.017341
std 50.084928 1687.753140 63354.613919 618.361022 28063.394844 40966.381219 0.230572 50675.002241 42869.655092 14648.179473 33160.941514 4112.803148 0.029967 11470.181802 9166.005235 14906.279740 21299.868863 23789.655363 6944.998579
min 1.000000 1100.000000 124.000000 2.000000 119.000000 0.000000 0.000000 0.000000 111.000000 0.000000 111.000000 0.000000 0.000000 22000.000000 18500.000000 22000.000000 0.000000 0.000000 0.000000
25% 44.000000 2403.000000 4361.000000 39.000000 2110.000000 1784.000000 0.339671 3608.000000 3154.000000 1030.000000 2453.000000 304.000000 0.050723 33000.000000 24000.000000 42000.000000 1675.000000 1591.000000 340.000000
50% 87.000000 3608.000000 15058.000000 130.000000 5347.000000 8284.000000 0.535714 11797.000000 10048.000000 3299.000000 7413.000000 893.000000 0.068272 36000.000000 27000.000000 47000.000000 4390.000000 4595.000000 1231.000000
75% 130.000000 5503.000000 38844.000000 338.000000 14440.000000 22456.000000 0.702020 31433.000000 25147.000000 9948.000000 16891.000000 2393.000000 0.087599 45000.000000 33000.000000 60000.000000 14444.000000 11783.000000 3466.000000
max 173.000000 6403.000000 393735.000000 4212.000000 173809.000000 307087.000000 0.968954 307933.000000 251540.000000 115172.000000 199897.000000 28169.000000 0.177226 110000.000000 95000.000000 125000.000000 151643.000000 148395.000000 48207.000000

In [15]:
# Remove missing values
print("Original: {0} rows x {1} columns".format(recent_grads.shape[0], recent_grads.shape[1]))
recent_grads.dropna(inplace=True)
print("After cleansed: {0} rows x {1} columns".format(recent_grads.shape[0], recent_grads.shape[1]))


Original: 173 rows x 21 columns
After cleansed: 172 rows x 21 columns

In [16]:
# Plot scatter matrix
from pandas.tools.plotting import scatter_matrix

scatter_matrix(recent_grads[["ShareWomen","Unemployment_rate"]])

plt.show()



In [17]:
# Plot grouped bar plot
# recent_grads["ShareMen"] = recent_grads["Men"] / recent_grads["Total"]
recent_grads["ShareMen"] = 1 - recent_grads["ShareWomen"]
arts = recent_grads[recent_grads["Major_category"] == "Arts"]
arts.set_index("Major", inplace=True)
sex_ratio = ["ShareMen", "ShareWomen"]
recent_grads.head(10)

yticks = np.arange(0, 1.4, 0.2)

arts[sex_ratio].plot(kind="bar", stacked=True, figsize=(6,6), yticks=yticks)
plt.show()



In [ ]: