import pandas as pd pieces = [] years = range(1880,2011) columns=['name','sex','births'] opath = "/Users/xuxp/learn-env/pydata-book-master/ch02/names" for year in years: path = "%s/yob%d.txt" % (opath,year) frame = pd.read_csv(path,names=columns) frame['year'] = year pieces.append(frame)
boys = top1000[top1000.sex == 'M'] girls = top1000[top1000.sex == 'F'] total_births = top1000.pivot_table('births',index='year',columns='name',aggfunc=sum) subset = total_births[['Minnie','Harry']] subset.plot(subplots=True,figsize=(12,10),grid=False,title="Number og births per year")
五、评估命名多样性的增长
1 2
table = top1000.pivot_table('prop',index='year',columns='sex',aggfunc=sum) table.plot(title='Sum of table1000.prop by year and sex',yticks=np.linspace(0,1.2,13),xticks=range(1880,2020,10))