Let say I have below dataframe
import pandas as pd
Dat = pd.DataFrame({'a' : [1,2], 'b' : [3,4]})
def MyFunc(x, y) :
return x + y ** (.5)
Now I want to apply above custom function to elements of each of the columns of Dat.
Is there any function/method to achieve this?
I have gone through different suggestions over internet, however all of them talk mainly application of standard python function e.g. sum()
Any pointer will be very helpful.
>Solution :
You don’t need a function, you can use directly:
Dat.iloc[0]+Dat.iloc[1]**.5
If really you need the function:
MyFunc(Dat.iloc[0], Dat.iloc[1])
Or:
tmp = Dat.T
MyFunc(tmp[0], tmp[1])
Output:
a 2.414214
b 5.000000
dtype: float64