%matplotlib inline
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt

# Load dataset
import zipfile
with zipfile.ZipFile('../datasets/baby-names2.csv.zip', 'r') as z:
    f = z.open('baby-names2.csv')
    names = pd.io.parsers.read_table(f, sep=',')

names.head()

names[names.year == 1993].head()    

"""
Explanation: Exercise 03
Analyze the baby names dataset using pandas
End of explanation
"""


boys = names[names.sex == 'boy'].copy()    
girls = names[names.sex == 'girl'].copy()

"""
Explanation: segment the data into boy and girl names
End of explanation
"""


william = boys[boys['name']=='William']

plt.plot(range(william.shape[0]), william['prop'])
plt.xticks(range(william.shape[0])[::5], william['year'].values[::5], rotation='vertical')
plt.ylim([0, 0.1])
plt.show()

Daniel = boys[boys['name']=='Daniel']

plt.plot(range(Daniel.shape[0]), Daniel['prop'])
plt.xticks(range(Daniel.shape[0])[::5], Daniel['year'].values[::5], rotation='vertical')
plt.ylim([0, 0.1])
plt.show()

"""
Explanation: Analyzing the popularity of a name over time
End of explanation
"""


