<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 MIE1624H Introductory Example
US Baby Names 2010
Step1:  http
Step2:  Total number of birth in year 2010 by sex
Step3:  Insert prop column for each group
Step4:  Verify that the prop clumn sums to 1 within all the groups
Step5:  Extract a subset of the data with the top 10 names for each sex
Step6:  Aggregate all birth by the first latter from name column
Step7:  Normalize the table
Step8:  Plot proportion of boys and girls names starting in each letter
<ASSISTANT_TASK:>
Python Code:
%pwd
Explanation: MIE1624H Introductory Example
US Baby Names 2010
End of explanation
import pandas as pd
names2010 = pd.read_csv('/resources/yob2010.txt', names=['name', 'sex', 'births'])
names2010
Explanation: http://www.ssa.gov/oact/babynames/limits.html
Load file into a DataFrame
End of explanation
names2010.groupby('sex').births.sum()
Explanation: Total number of birth in year 2010 by sex
End of explanation
def add_prop(group):
    # Integer division floors
    births = group.births.astype(float)
    group['prop'] = births / births.sum()
    return group
names2010 = names2010.groupby(['sex']).apply(add_prop)
names2010
Explanation: Insert prop column for each group
End of explanation
import numpy as np
np.allclose(names2010.groupby(['sex']).prop.sum(), 1)
Explanation: Verify that the prop clumn sums to 1 within all the groups
End of explanation
def get_top10(group):
    return group.sort_index(by='births', ascending=False)[:10]
grouped = names2010.groupby(['sex'])
top10 = grouped.apply(get_top10)
top10.index = np.arange(len(top10))
top10
Explanation: Extract a subset of the data with the top 10 names for each sex
End of explanation
# extract first letter from name column
get_first_letter = lambda x: x[0]
first_letters = names2010.name.map(get_first_letter)
first_letters.name = 'first_letter'
table = names2010.pivot_table('births', index=first_letters,
                          columns=['sex'], aggfunc=sum)
table.head()
Explanation: Aggregate all birth by the first latter from name column
End of explanation
table.sum()
letter_prop = table / table.sum().astype(float)
Explanation: Normalize the table
End of explanation
%matplotlib inline
import matplotlib.pyplot as plt
fig, axes = plt.subplots(2, 1, figsize=(10, 8))
letter_prop['M'].plot(kind='bar', rot=0, ax=axes[0], title='Male')
letter_prop['F'].plot(kind='bar', rot=0, ax=axes[1], title='Female',
                      legend=False)
Explanation: Plot proportion of boys and girls names starting in each letter
End of explanation
<END_TASK>