I have a KPI with a formula to calculate, what I do is actually calculate the value of the KPI for the whole population (2245 individuals or input), the formula is:

v1+v2+v3 / a1+a2+a3

Where vi and ai are the sum of all the values of the variable for every input, i.e for example v1 represents the sum of all the 2245 values of v1.

After that I want to know how does the KPI change if I remove one input from the population, so what I do is calculate vi and ai without that input, and then calculate the KPI again. (I do it for all inputs)

I do this with excel for the moment and it is quite manual, I want to know if there's a function in R or Python that would allow me to do that.

Any help would be appreciated, thank you.


1 Answer 1


If you load your columns into a pandas dataframe you can do the following:

import pandas as pd

#prepare toy dataset
n = 2245
v1, v2, v3, a1, a2, a3 = np.random.rand(6,n).tolist()
df = pd.DataFrame([v1,v2,v3,a1,a2,a3]).T
df.columns = ['v1','v2','v3','a1','a2','a3']

kpis = []
for i in range(n):
    #select all values except the current one
    new_df = df.loc[df.index.difference(pd.Index([i]))] 

    #3xN matrices
    right = new_df.T.loc[['a1','a2','a3']]
    left = new_df.T.loc[['v1','v2','v3']]
    #squash them into 1xN and sum again to get a number
    left = (left.sum()).sum()
    right = (right.sum()).sum()

    kpi = left/right

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.