I have a data frame in python as shown in the screenshot. the logic for desire output is basically for each product ID, first year value[0]=max(cumulative profit[0],0), subsequent year it is max(0, cumulative profit[i]-sum of values in earlier years. this logic need to be applied to each product ID. can someone please help? I have tried a few ways like using double loop. no success so far. Many thanks. [dataframe][1]
df=pandas.dataframe({'Product ID':['A','A','A','A','B','B','C'],'Year':[1,2,3,4,1,2,1],'Cumulative Profit':[10,8,12,18,-5,10,2],'Desired output':[10,0,2,6,0,10,2]})