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

  • 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. https://stackoverflow.com/questions/13256917/pandas-creating-aggregated-column-in-dataframe – Jonathan Leon Dec 27 '20 at 17:41
  • agg({'avg': np.average, 'sum': np.sum}) -> is supposed to add columns avg and sum itself – rohit rasam Dec 27 '20 at 17:43
  • 2
    i don't believe that is correct: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.agg.html If you change avg and sum to the columns you want to perform that on, it would work – Jonathan Leon Dec 27 '20 at 17:46
  • Jonathan is right. The keys of the dict passed to agg must be existing columns names. – Ismael EL ATIFI Dec 27 '20 at 20:17

0 Answers0