《利用Python进行数据分析》第二章pivot

xiaoxiao2021-02-28  34

学习《利用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'

参考http://blog.csdn.net/Zhangjunjie789/article/details/47724813,将rows改成index,cols写成全名”columns”:

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

便可得到正确处理结果:

转载请注明原文地址: https://www.6miu.com/read-2621949.html

最新回复(0)