<jupyter_start><jupyter_text>Post Grad Income Data by State:  Investigating whether or not different properties of colleges change based on location of the school <NAME> & <NAME>  Importing the data<jupyter_code>import pandas as pd
import numpy as np
import plotly_express as px
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.figure_factory as ff


college_income_stats = pd.read_csv('Most-Recent-Cohorts-All-Data-Elements.csv') 
college_income_stats.head()<jupyter_output>/optnfs/el7/jupyterhub/envs/Psych81.09/lib/python3.6/site-packages/IPython/core/interactiveshell.py:3044: DtypeWarning:

Columns (6,9,987,988,989,990,991,992,993,994,995,996,997,998,999,1000,1001,1002,1003,1004,1005,1006,1008,1009,1010,1011,1014,1015,1016,1017,1018,1019,1021,1022,1023,1027,1028,1029,1030,1031,1032,1034,1035,1036,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1065,1066,1067,1068,1069,1070,1071,1073,1074,1075,1076,1078,1079,1080,1081,1082,1083,1084,1086,1087,1088,1089,1091,1092,1093,1094,1095,1096,1097,1099,1100,1101,1102,1104,1105,1106,1107,1108,1109,1110,1112,1113,1114,1115,1118,1119,1121,1122,1123,1125,1127,1128,1131,1132,1134,1135,1136,1138,1140,1141,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,1154,1157,1158,1159,1160,1161,1162,1163,1164,1165,1166,1167,1170,1171,1172,1173,1174,1175,1177,1178,1179,1180,1183,1184,1185,1186,1187,1188,1190,1192,1196,1199,1200,1201,1209,1212,1213,1214,1222,1223,1224,1225[...]<jupyter_text>Cleaning the data<jupyter_code>college_income_stats.columns
#Chose to only look at income information 10 years after graduation. 
x = ['UNITID','INSTNM','STABBR','ZIP','LATITUDE','LONGITUDE','PCT_WHITE','PCT_BLACK','PCT_ASIAN','PCT_HISPANIC','MN_EARN_WNE_P10','MD_EARN_WNE_P10']
college_income_stats[x]
clean_data = college_income_stats[x].set_index(['UNITID','INSTNM'])
clean_data2 = clean_data.fillna(0)
clean_data2.head()<jupyter_output><empty_output><jupyter_text>Descriptive statistics<jupyter_code>#First, we converted the data into numeric data
numeric_data = clean_data2[['PCT_WHITE','PCT_BLACK','PCT_ASIAN','PCT_HISPANIC','MN_EARN_WNE_P10','MD_EARN_WNE_P10']] = clean_data2[['PCT_WHITE','PCT_BLACK','PCT_ASIAN','PCT_HISPANIC','MN_EARN_WNE_P10','MD_EARN_WNE_P10']].apply(pd.to_numeric, errors='coerce')
numeric_data.head()
#Then, we calculated the max, min, mean and median
numeric_data.max()
numeric_data.min()
numeric_data.median()
numeric_data.mean()<jupyter_output><empty_output><jupyter_text>Data Visualization<jupyter_code>x1 = clean_data2['STABBR']
final_data = numeric_data.copy()
final_data['STATE']= x1.tolist()

final_data.head()

by_state=final_data.groupby('STATE').aggregate(np.mean)
by_state.head(10)
#Stacked bar plot of average state demographic composition
state = by_state.index
White = by_state['PCT_WHITE']
Black = by_state['PCT_BLACK']
Asian = by_state['PCT_ASIAN']
Hispanic = by_state['PCT_HISPANIC']
ind = [x for x, _ in enumerate(state)]
stackedbarplot = plt.figure(figsize=(18,8))
plt.bar(ind, White, width=0.5, label='White', color='Red', bottom=Black+Asian+Hispanic)
plt.bar(ind, Black, width=0.5, label='Black', color='Blue', bottom=Asian+Hispanic)
plt.bar(ind, Asian, width=0.5, label='Asian', color='Yellow', bottom=Hispanic)
plt.bar(ind, Hispanic, width=0.5, label='Hispanic', color='Green')


plt.xticks(ind, state)
plt.ylabel("Demographics")
plt.xlabel("State")
plt.legend(loc="upper right")
plt.title("Institution Demographics by State")
plt.show()
#Bar plot of average median income by state
state = by_state.index
median = by_state['MD_EARN_WNE_P10']

state_pos = [i for i, _ in enumerate(state)]
barplot = plt.figure(figsize=(18,8))
plt.bar(state_pos, median,width=0.5, color='Purple')
plt.xlabel("State")
plt.ylabel("Average Median Income")
plt.title("Average Median Income by State")

plt.xticks(state_pos, state)

plt.show()
#States with 10 highest average median incomes
by_state_sorted = by_state.sort_values(['MD_EARN_WNE_P10'], ascending=False)
by_state_sorted.head(10)
#Examining the relationship between demographic percentages and median income
wpop=by_state['PCT_WHITE']
bpop=by_state['PCT_BLACK']
asianpop=by_state['PCT_ASIAN']
hispanicpop=by_state['PCT_HISPANIC']
x=by_state['MD_EARN_WNE_P10']
plt.figure(figsize=(18,8))
plt.scatter(x, wpop, color='red')
plt.scatter(x, bpop, color='blue')
plt.scatter(x, asianpop,color='yellow')
plt.scatter(x, hispanicpop, color='green')
plt.xlabel('Avg Median Income')
plt.ylabel('Percent')
plt.title('Demographics vs. Avg Median Income')
plt.legend(loc="upper right")
plt.show()<jupyter_output><empty_output><jupyter_text>Comparing top 10 earning states and top 10 in each demographic category<jupyter_code>by_state_sorted2= by_state.sort_values(['PCT_WHITE'], ascending=False)
by_state_sorted2.head(10)<jupyter_output><empty_output><jupyter_text>States that fall in the top 10 for both median income and percent white population include:MN, VT, IA, NE<jupyter_code>by_state_sorted3= by_state.sort_values(['PCT_BLACK'], ascending=False)
by_state_sorted3.head(10)<jupyter_output><empty_output><jupyter_text>States that fall in the top 10 for both median income and percent black population include: DC<jupyter_code>by_state_sorted4= by_state.sort_values(['PCT_ASIAN'], ascending=False)
by_state_sorted4.head(10)<jupyter_output><empty_output><jupyter_text>States that fall in the top 10 for both median income and percent asian population include: NY<jupyter_code>by_state_sorted5= by_state.sort_values(['PCT_HISPANIC'], ascending=False)
by_state_sorted5.head(10)<jupyter_output><empty_output><jupyter_text>States that fall in the top 10 for both median income and percent asian population include: N/A<jupyter_code>map_data = numeric_data.copy()
map_data['LATITUDE']=clean_data2['LATITUDE']
map_data['LONGITUDE']=clean_data2['LONGITUDE']
map_data['STATE']=clean_data2['STABBR']
map_data.head()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup