学习《利用Python进行数据分析》第二章的时候,处理1880-2010年间全美婴儿姓名数据,有句代码总是报错:

total_births=names.pivot_table('births',rows='year',cols='sex',aggfunc=sum)1

报错信息如下:

Traceback (most recent call last):


  File "<ipython-input-75-8bbcd2a6b8ca>", line 1, in <module>
    total_births=names.pivot_table('births',rows='year',cols='sex',aggfunc=sum)


TypeError: pivot_table() got an unexpected keyword argument 'rows'12345678

查了有关资料,将rows改成index,cols写成全名”columns”:

total_births=names.pivot_table('births',index='year',columns='sex',aggfunc=sum) 1

便可得到正确处理结果:

这里写图片描述