I have created the function below which returns a vector based on two input vectors. I have a pandas dataframe with different columns and I would like to apply that function to some columns of my dataframe (one pandas column would be the first vector of my function (nominal), another one the second vector of my function(CPI) and I would assign the result of my function to a new pandas column). How could I do it?
Thank you very much for your help,
Pierre
nominal=[10,10,10,10,10,10,10,10,10,10,10,10]
CPI=[0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02,0.02]
def nominal_to_real(nominal,CPI):
real=[]
product=1
for i in range(len(nominal)):
product*=(CPI[i]+1)**(1/12)
real.append(nominal[i]/product)
return real
nominal_to_real(df.nominal, df.CPI)? But note, your function returns a list that has one more element than your input lists... so I'm not sure how you expect this to behave with a data-frame...