0

I would like to sum up values in my panda datagram based on the values of two columns. (Python 3.x)

I already tried to use the groupby functions and similar approaches, but as I am relatively new to the topic I need some help.

This is the an example of the data I work with:

Date         |   ID   | Count
2019-01-01   | 300020 | 1
2019-01-01   | 300020 | 1
2019-01-01   | 300020 | 1
2019-02-01   | 660020 | 1
2019-02-01   | 300020 | 1
2019-03-01   | 760020 | 1
2019-03-01   | 300020 | 1
2019-03-01   | 300020 | 1
2019-03-01   | 760020 | 1

And the end result should be:

Date         |   ID   | Count
2019-01-01   | 300020 | 3
2019-02-01   | 660020 | 1
2019-02-01   | 300020 | 1
2019-03-01   | 760020 | 2
2019-03-01   | 300020 | 2

Any help would be appreciated!

1 Answers1

2

This is more like groupby

yourdf=df.groupby(['Date','ID'],sort=False, as_index=False)['Count'].sum()
BENY
  • 317,841
  • 20
  • 164
  • 234
  • instead of `yourdf`, you can use `df['name_of_newColumn']` to get the values in a new column in the same dataframe – moys Aug 26 '19 at 01:43