0

I have a dataframe:

df = pd.DataFrame([{'y': 2019, 'pop': 234}, {'y': 2018, 'pop': 23}, {'y': 2017, 'pop': 2444}, {'y': 2018, 'pop': 12}, {'y': 2019, 'pop': 22}])

I want to create a new dataframe where the pop is summed based on the year:

years = df['y'].unique()    
df2 = pd.DataFrame([{'y': 2019, 'pop': 256}, {'y': 2018, 'pop': 35}, {'y': 2017, 'pop': 2444}])
Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
Evan Brittain
  • 547
  • 5
  • 15

0 Answers0