1

I have a percentile dataframe df as follows:

            col1   col2   col3      
GDStart                                                                   
2019-09-02  100    11     12  
2019-09-03   60    16     14  
2019-09-04   60    67     13  

and an external function as:

import numpy as np
def Fn(x, a):
 return np.percentile(x, a)

I want to get apply my custom Fn to each row of df to get median for each row. I am expecting the following answer when using np.percentile(x, 50) i.e. median for each row:

         col1
GDStart                                                                   
2019-09-02   12
2019-09-03   16
2019-09-04   60

I am not sure how to apply the lambda or apply function here. My situation is tricky as I might need to find 30th percentile, or 50th percentile etc; a changes.

Zanam
  • 4,286
  • 11
  • 53
  • 114

1 Answers1

2

Pass the keywords to apply

It will pass it along to the function

df.apply(Fn, a=.5, axis=1)

Pass the positional arguments

df.apply(Fn, args=(.5,), axis=1)
piRSquared
  • 265,629
  • 48
  • 427
  • 571