Skip to content Skip to sidebar Skip to footer

Pandas Resampling Using Numpy Percentile?

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

Solution 1:

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

Post a Comment for "Pandas Resampling Using Numpy Percentile?"