Harichandana
Harichandana

Reputation: 11

How do I solve SpecificationError: nested renamer is not supported

I am using agg function and using parameter as a dictionary on my dataframe. But I am getting the nested renamer is not supported error. I am executing the code in google colab notebook.

Code:

gb_agg = gb.agg({'Yield' : {'Count' : lambda x: len(x.unique())}})
diff_counties_2013 = gb_agg[gb_agg['Yield']['Count'] > 1].index.get_level_values('CountyName').values
gb_agg[gb_agg['Yield']['Count'] > 1]

Error:

<ipython-input-12-67897b1ec868> in <module>()
      1 
      2 gb = df_2013.groupby(by='CountyName')
----> 3 gb_agg = gb.agg({'Yield' : {'Count' : lambda x: len(x.unique())}})
      4 diff_counties_2013 = gb_agg[gb_agg['Yield']['Count'] > 1].index.get_level_values('CountyName').values
      5 gb_agg[gb_agg['Yield']['Count'] > 1]

1 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/base.py in _aggregate(self, arg, *args, **kwargs)
    336                     # {'ra' : { 'A' : 'mean' }}
    337                     if isinstance(v, dict):
--> 338                         raise SpecificationError("nested renamer is not supported")
    339                     elif isinstance(obj, ABCSeries):
    340                         raise SpecificationError("nested renamer is not supported")

SpecificationError: nested renamer is not supported

Upvotes: 1

Views: 1876

Answers (1)

Scott Boston
Scott Boston

Reputation: 153510

Let's use pd.NamedAgg since nested renamer was deprecated in pandas 0.25.0.

df_2013.groupby(by='CountyName').agg(Count=('Yeild','count'))

OR

df_2013.groupby(by='CountyName').agg(Count=('Yeild', lambda x: len(x.unique())))

Upvotes: 1

Related Questions