-1

I am trying to add values together for each year in my dataset.

The dataframe looks like..

enter image description here

I'd like to add the values in NUMBER OF MOSQUITOES column, collect them in the year to which it belongs.

For example,

2007 395
2008 154
2009 353
...
...
...

Which methods in pandas or numpy can I use?

Thank you for your help in advance

Liu Bei
  • 565
  • 3
  • 9
  • 19

2 Answers2

1

If I'm understanding correctly, you want to sum the number of mosquitoes in every year. If that's the case, you can use groupby.sum(), like this:

df.groupby(['SEASON YEAR'], as_index=False).sum()

I'm not sure if that's what you're looking for, tell me otherwise.

Juan C
  • 5,846
  • 2
  • 17
  • 51
  • Thank you very much, sir. This would be another way to sum them. Very appreciated by your help. – Liu Bei Aug 01 '18 at 21:02
1

You can simply do groupby and sum:

df.groupby("SEASON YEAR").sum()["NUMBER OF MOSQUITOES"]
TYZ
  • 8,466
  • 5
  • 29
  • 60