一、问题描述
使用gropuby+agg分组+聚合函数做词频统计时,出现SpecificationError: nested renamer is not supported错误。
二、解决
出错代码为:
words_count=df_all_words.groupby(by=['all_words'])['all_words'].agg({"count":numpy.size})
修改为:
words_count=df_all_words.groupby(by=['all_words'])['all_words'].agg([("count","count")])
运行结果:
Life is like a box of chocolates, you never know what you are going to get.