0

I have the following dataframe:

df = pd.DataFrame({'team': ['a', 'a', 'b', 'b', 'b', 'c', 'c'],
                   'points': [5, 8, 14, 18, 5, 7, 7]})

I want to create a column 'test' which sums all points with respect to its team. I know the groupby function works to give a summary:

Input

df.groupby('team')['points'].sum()

Output

team
a    13
b    37
c    14
Name: points, dtype: int64

However, I want those values on each rows, just like in Excel when using SUMIF function. Find an example of output here: https://i.stack.imgur.com/uAgyF.png

Any idea how to do this?

Franz
  • 1
  • 1

0 Answers0