<jupyter_start><jupyter_text>Mental Health Services<jupyter_code>dh.YEAR.value_counts()
#group the mental health services data by year and state(LST)
grouped_ys = dh.groupby(['YEAR','LST'], sort=True).agg({'LST': len}).rename(columns={'LST':'NProviders'}).reset_index()
grouped_ys
#top 10 from 2010
g2010 = grouped_ys.groupby(['YEAR']).get_group(2010).reset_index()[['LST','NProviders']].sort_values(by=['NProviders'], ascending=False).head(10)
g2010
#function for labeling
def autolabel(rects):
    """
    Attach a text label above each bar displaying its height
    """
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
                '%d' % int(height),
                ha='center', va='bottom')
width = 0.50 

fig, ax = plt.subplots()
serv10 = ax.bar(np.arange(10), g2010['NProviders'], width, color='r')

ax.set_xticks(np.arange(10) + width / 2)
ax.set_xticklabels(('CA','NY','PA','IL','OH','FL','MI','TX','MA','IN'))

ax.set_ylabel('Number of hospital/service')
ax.set_xlabel('State')
ax.set_title('States with High MH Services Available in 2010')

autolabel(serv10)
plt.savefig('s2010.jpg')
#top 10 from 2012
g2012 = grouped_ys.groupby(['YEAR']).get_group(2012).reset_index()[['LST','NProviders']].sort_values(by=['NProviders'], ascending=False).head(10)
g2012
width = 0.50 

fig, ax = plt.subplots()
serv12 = ax.bar(np.arange(10), g2012['NProviders'], width, color='b')
ax.set_xticks(np.arange(10) + width / 2)
ax.set_xticklabels(('NY','CA','NC','WI','OH','PA','IL','FL','MA','MI'))

ax.set_ylabel('Number of hospital/service')
ax.set_xlabel('State')
ax.set_title('States with High MH Services Available in 2012')

autolabel(serv12)
plt.savefig('s2012.jpg')
#top 10 from 2014
g2014 = grouped_ys.groupby(['YEAR']).get_group(2014).reset_index()[['LST','NProviders']].sort_values(by=['NProviders'], ascending=False).head(10)
g2014
width = 0.50 

fig, ax = plt.subplots()
serv14 = ax.bar(np.arange(10), g2014['NProviders'], width, color='g')
ax.set_xticks(np.arange(10) + width / 2)
ax.set_xticklabels(('NY','CA','PA','OH','FL','IL','WI','AZ','NC','MI'))

ax.set_ylabel('Number of hospital/service')
ax.set_xlabel('State')
ax.set_title('States with High MH Services Available in 2014')

autolabel(serv14)
plt.savefig('s2014.jpg')<jupyter_output><empty_output><jupyter_text>admission<jupyter_code>ya.head(5)
grouped_yst = da.groupby(['YEAR','STFIPS'], sort=True).agg({'STFIPS': len}).rename(columns={'STFIPS':'NAdmissions'}).reset_index()
#top 10 from 2010
a2010 = grouped_yst.groupby(['YEAR']).get_group(2010).reset_index()[['STFIPS','NAdmissions']].sort_values(by=['NAdmissions'], ascending=False).head(10)
a2010
width = 0.50 

fig, ax = plt.subplots()
rects1 = ax.bar(np.arange(10), a2010['NAdmissions'], width, color='r')

ax.set_xticks(np.arange(10) + width / 2)
ax.set_xticklabels(('NY','CA','MA','OH','CO','IL','NJ','PA','MI','FL'))

ax.set_ylabel('Number of admission')
ax.set_xlabel('State')
ax.set_title('States with Highest Admission Rate in 2010')

autolabel(rects1)
plt.savefig('a2010.jpg')
data_frame.LST.unique()
#top 10 from 2011
a2011 = grouped_yst.groupby(['YEAR']).get_group(2011).reset_index()[['STFIPS','NAdmissions']].sort_values(by=['NAdmissions'], ascending=False).head(10)
a2011
width = 0.50 

fig, ax = plt.subplots()
rects2 = ax.bar(np.arange(10), a2011['NAdmissions'], width, color='y')
ax.set_xticks(np.arange(10) + width / 2)
ax.set_xticklabels(('NY','CA','FL','MA','OH','CO','NJ','MD','CT','NC'))

ax.set_ylabel('Number of admission')
ax.set_xlabel('State')
ax.set_title('States with Highest Admission Rate in 2011')

autolabel(rects2)
plt.savefig('a2011.jpg')
#top 10 from 2012
a2012 = grouped_yst.groupby(['YEAR']).get_group(2012).reset_index()[['STFIPS','NAdmissions']].sort_values(by=['NAdmissions'], ascending=False).head(10)
a2012
width = 0.50 

fig, ax = plt.subplots()
rects3 = ax.bar(np.arange(10), a2012['NAdmissions'], width, color='brown')
ax.set_xticks(np.arange(10) + width / 2)
ax.set_xticklabels(('NY','CA','MA','CO','NJ','OH','FL','MD','CT','NC'))

ax.set_ylabel('Number of admission')
ax.set_xlabel('State')
ax.set_title('States with Highest Admission Rate in 2012')

autolabel(rects3)
plt.savefig('a2012.jpg')
#top 10 from 2013
a2013 = grouped_yst.groupby(['YEAR']).get_group(2013).reset_index()[['STFIPS','NAdmissions']].sort_values(by=['NAdmissions'], ascending=False).head(10)
a2013
width = 0.50 

fig, ax = plt.subplots()
rects4 = ax.bar(np.arange(10), a2013['NAdmissions'], width, color='pink')
ax.set_xticks(np.arange(10) + width / 2)
ax.set_xticklabels(('NY','CA','MA','NJ','CO','CT','OH','MI','MN','NC'))

ax.set_ylabel('Number of admission')
ax.set_xlabel('State')
ax.set_title('States with Highest Admission Rate in 2013')

autolabel(rects4)
plt.savefig('a2013.jpg')
#top 10 from 2014
a2014 = grouped_yst.groupby(['YEAR']).get_group(2014).reset_index()[['STFIPS','NAdmissions']].sort_values(by=['NAdmissions'], ascending=False).head(10)
a2014
width = 0.50 

fig, ax = plt.subplots()
rects5 = ax.bar(np.arange(10), a2014['NAdmissions'], width, color='yellow')
ax.set_xticks(np.arange(10) + width / 2)
ax.set_xticklabels(('NY','CA','MA','CO','CT','NJ','MI','MN','OH','GA'))

ax.set_ylabel('Number of admission')
ax.set_xlabel('State')
ax.set_title('States with Highest Admission Rate in 2014')

autolabel(rects5)
plt.savefig('a2014.jpg')
joined = pd.merge(a2010, a2011, on='STFIPS')
joined = pd.merge(joined, a2012, on='STFIPS')
joined = pd.merge(joined, a2013, on='STFIPS')
joined = pd.merge(joined, a2014, on='STFIPS')

joined.columns = ['STFIPS', 'y2010', 'y2011', 'y2012', 'y2013', 'y2014']

joined
width = 0.15 
ind = np.arange(6)

fig, ax = plt.subplots()
y2010 = ax.bar(ind, joined['y2010'], width, color='r')
y2011 = ax.bar(ind+width, joined['y2011'], width, color='y')
y2012 = ax.bar(ind+2*width, joined['y2012'], width, color='brown')
y2013 = ax.bar(ind+3*width, joined['y2013'], width, color='pink')
y2014 = ax.bar(ind+4*width, joined['y2014'], width, color='yellow')

ax.set_title('States with Highest Admission Rate 2010-2014')
ax.set_xlabel('State')
ax.set_ylabel('Number of admission')

ax.set_xticks(ind+4*width / 2)
ax.set_xticklabels(('New York', 'California', 'Massachusetts', 'Ohio', 'Colorado', 'New Jersey'))

ax.legend((y2010[0], y2011[0], y2012[0], y2013[0], y2014[0]), ('2010', '2011', '2012', '2013', '2014'))
ax.grid(True)

plt.savefig('Top6 admission.jpg')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2158139534883721, 'fraction_numerical': 0.07596899224806201, 'mean_word_length': 7.17617237008872, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '271505', 'license': 'MIT', 'n_tokens_mistral': 2931, 'n_tokens_neox': 2502, 'n_words': 423, 'path': 'week2/State-wise.ipynb', 'repo_name': 'rve/DM-Lab', 'size': '6450'}