There is a DataFrame 'result_data':

ind Name Date Value 0 Black 01.01.2018 15 1 Wick 08.01.2018 74 2 Jeff 09.01.2018 31 3 Wick 16.01.2018 26 4 Jeff 18.01.2018 74 5 Anit 20.01.2018 56 6 Anit 21.01.2018 78 7 Wick 30.01.2018 10 

For each line, it is necessary to calculate the sum of the value over the whole df, where the name = name of this line, and date <= date of this line. Those. get something like this:

 ind Name Date Value Result 0 Black 01.01.2018 15 15 1 Wick 08.01.2018 74 74 2 Jeff 09.01.2018 31 31 3 Wick 16.01.2018 26 100 4 Jeff 18.01.2018 74 105 5 Anit 20.01.2018 56 56 6 Anit 21.01.2018 78 134 7 Wick 30.01.2018 10 110 

A trivial task, but it does not work to solve it.

    1 answer 1

    Use groupby.DataFrameGroupBy.cumsum () :

     In [156]: df['Result'] = df.sort_values('Date').groupby('Name')['Value'].cumsum() In [157]: df Out[157]: ind Name Date Value Result 0 0 Black 01.01.2018 15 15 1 1 Wick 08.01.2018 74 74 2 2 Jeff 09.01.2018 31 31 3 3 Wick 16.01.2018 26 100 4 4 Jeff 18.01.2018 74 105 5 5 Anit 20.01.2018 56 56 6 6 Anit 21.01.2018 78 134 7 7 Wick 30.01.2018 10 110