0

I want to get Average and Sum of POPESTIMATE2010 and POPESTIMATE2011 which is in the dataframe. But when i give this Code its just showing the sum of both the Columns separately . But average is not getting displayed . How do i get the average also ? The way i want my output is STNAME, POPESTIMATE2010AVG,POPESTIMATE2011AVG,POPESTIMATE2010sum, POPESTIMATE2011sum

(df.set_index('STNAME').groupby(level=0)['POPESTIMATE2010','POPESTIMATE2011']
    .agg({'POPESTIMATE2010': np.average, 'POPESTIMATE2011': np.average,'POPESTIMATE2010':np.sum,'POPESTIMATE2011':np.sum}))
Sargis
  • 1,196
  • 1
  • 18
  • 31
  • Problem is in `{'POPESTIMATE2010': np.average, 'POPESTIMATE2011': np.average,'POPESTIMATE2010':np.sum,'POPESTIMATE2011':np.sum}`, `keys` of dict has to be always unique, so need dictionary of lists with unique `keys` – jezrael Feb 28 '20 at 08:05
  • ooh yes .. exactly.. But how do we modify the code according to the requirement. – Krishna Girish Feb 29 '20 at 07:16

0 Answers0