0

The code from the tutorial

 (df.set_index('STNAME').groupby(level=0)['CENSUS2010POP']
     .agg({'sum': np.sum, 'avg': np.average}))

I am getting the following error while using the above code: nested renamer is not supported

My code is having the above mentioned error

4
  • are sum and avg current column names? If not, try adding them to df first, then running your code. This shows alternatives to your method that may work as well. stackoverflow.com/questions/13256917/… Commented Dec 27, 2020 at 17:41
  • agg({'avg': np.average, 'sum': np.sum}) -> is supposed to add columns avg and sum itself Commented Dec 27, 2020 at 17:43
  • 2
    i don't believe that is correct: pandas.pydata.org/pandas-docs/stable/reference/api/… If you change avg and sum to the columns you want to perform that on, it would work Commented Dec 27, 2020 at 17:46
  • Jonathan is right. The keys of the dict passed to agg must be existing columns names. Commented Dec 27, 2020 at 20:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.