# Deduct a value based on multiple relationships/conditions [closed]

A Father of three sons and a grandfather of 10 is in the last stages of his life. He wants to give his assets to his grandchildren (After allocating the asset, they can sell them, of course). He explained his lawyer following conditions(A strict grandfather).

1. Oldest among his children get the priority
2. Oldest grandchild of oldest son get the priority
3. The Person selected using the above two conditions get the most liquid asset or the realization order (Details Given under the â€˜DetailsAssetâ€™ Dataframe).
4. The above offer is based on how much money each grandchild has saved up to now a) Say one person has no savings, then no property is allocated to him/her. b) Say another person has savings of USD 100, grandfather will allocate up to USD 100 only. c) Any remaining security value goes to the next grandchild inline.

Expected outcome. Pandas/Python should calculate the remaining asset value after allocating to a person based above condition. I have used the following methods to solve the problems.

1. Pandas groupby and cumsum menthod I could not get the intended result.

DataFrames used in the computation 1)

DetailsChildred = pd.DataFrame({'Grand_Children':['Josh','Amal','Shivan','More','Angel','Robot'],\
'Children':['Mr Deen','Mr Deen','Mr Deen','Mr Jecop','Mr Jecop','Mr Jecop'],\
'Age_(Children)':[60,'','',55,'',''],'Age_(Grand_Children)':[35,30,25,20,40,29]})

DetailsAssets = pd.DataFrame({'Unique_Asset_id':['959CASH','960HOUSE','961SHARE','962CASH','963SHARE'],\
'Asset_Description':['DEPOSIT','HOUSE','SHARES','DEPOSIT','SHARES'],\
'Value_of_Asset':[54000,200000,250,500,250],\
'Realisation_Order':[1,3,2,1,2]})