2

Have you ever used the percentile numpy function when using the pandas function resample??

Considering that "data" is a dataframe with just one column with 10min data, I would like to do something like this:

dataDaily=data.resample('D',how=np.percentile(data['Col1'],q=90)

I got the following error:

'numpy.float64' object is not callable

Have you ever try this?

1 Answers1

6

You have to pass function to how parameter, not value. I think in your case you can use anonymous function (lambda function):

dataDaily = data.resample('D', how=lambda x: np.percentile(x['Col1'], q=90))

example:

>>> df = pd.DataFrame({'Col1': np.random.randn(10)})
>>> df.index = map(pd.Timestamp, ['20130101', '20130102']) * 5)
>>> df
                Col1
2013-01-01 -0.636815
2013-01-02 -0.028921
2013-01-01  0.643083
2013-01-02  0.065096
2013-01-01  0.446963
2013-01-02  0.462307
2013-01-01  2.768514
2013-01-02 -1.406168
2013-01-01  0.732656
2013-01-02 -0.699028
>>> df.resample('D', how=lambda x: np.percentile(x['Col1'], q=90))
                Col1
2013-01-01  1.954171
2013-01-02  0.303423
Roman Pekar
  • 107,110
  • 28
  • 195
  • 197