日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

pandas.core.base.SpecificationError: nested renamer is not supported

發布時間:2023/12/29 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pandas.core.base.SpecificationError: nested renamer is not supported 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天跟著老師寫爬蟲的時候發現報了個錯,但是發現代碼也沒錯,搞了半天之后發現是版本的原因

Traceback (most recent call last):
File “E:/code/python/PyCharm/bigdata/class/20201006/爬取豆瓣小說.py”, line 76, in
df_gp = df.groupby(by=[‘等級’])[‘star’].agg({‘人數’: np.size, ‘平均值’: np.mean, ‘最高分’: np.max, ‘最低分’: np.min})
File “E:\environment\Python\Python17-32\lib\site-packages\pandas\core\groupby\generic.py”, line 246, in aggregate
ret = self._aggregate_multiple_funcs(func)
File “E:\environment\Python\Python17-32\lib\site-packages\pandas\core\groupby\generic.py”, line 292, in _aggregate_multiple_funcs
raise SpecificationError(“nested renamer is not supported”)
pandas.core.base.SpecificationError: nested renamer is not supported

最后發現是pandas在 1.0版本后,更新了API寫法——gropuby+agg分組+聚合函數的寫法變了

首先,查看自己的pandas的版本,如果是1版本且報錯如上,則課根據以下方法改

import pandas as pd print (pd.__version__) # 我的是1.1.3

報錯的代碼片段

df_gp = df.groupby(by=['等級'])['star'].agg({'人數': np.size, '平均值': np.mean, '最高分': np.max, '最低分': np.min})

更改之后的代碼片段

df_gp = df.groupby(by=['等級'])['star'].agg([('人數', np.size), ('平均值', np.mean), ('最高分', np.max), ('最低分', np.min)])

總結

以上是生活随笔為你收集整理的pandas.core.base.SpecificationError: nested renamer is not supported的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。