I use a dataframe (NewList) to calculate a variable (NPQ), and then I would like to save this variable (which is a list) into a column in the original dataframe. I get an error.
def NPQ_calculation(NewList): #this is the dataframe
Fm_prime = NewList.iloc[0:7, 1] #2nd column in dataframe
NPQ = []
NPQ.append(Fm/Fm_prime - 1) #Fm is the 4th column in dataframe
return NPQ # this is the variable I want to add
# call function for NPQ calculation
NPQ = NPQ_calculation(NewList)
###PROBLEM
NewList['NPQ']= NPQ
This is the error message I get:
ValueError: Length of values does not match length of index
This is the original data frame to which I would like to add the new column (NPQ) [![I use the 2nd and 4th column to make the calculation of NPQ and would like to add the result in the last column][2]][2])