Basically im trying to use a user defined function to calculate values in a row in each dataframe and presenting them to a new column ABCD.
dfx = pd.DataFrame({'A': [1,2,3,4,5], 'B': [10,20,30,40,50], 'C':
[5,5,5,5,5], 'D' : [2,2,2,2,2]})
print(df)
A B C D E(Desired)
0 1 10 5 2
1 2 20 5 2
2 3 30 5 2
3 4 40 5 2
4 5 50 5 2
def functionx(A,B,C,D):
print( A * B + C / D)
dfx['ABCD'] = functionX
i tried using functionX but it does not work. How do i pass the function correctly through each row and produce a column E which is the result?
dfx["E"] = dfx.A * dfx.B + dfx.C / dfx.D. However, you want to apply a specific function row per row, have a look atapply