使用numpy百分位数对 pandas 进行重采样? [英] Pandas resampling using numpy percentile?
本文介绍了使用numpy百分位数对 pandas 进行重采样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用pandas函数重采样时,您曾经使用过百分位numpy函数吗?
Have you ever used the percentile numpy function when using the pandas function resample??
考虑到数据"是一个只有10分钟数据的一列的数据框,我想做这样的事情:
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)
我遇到以下错误:
'numpy.float64' object is not callable
您尝试过吗?
推荐答案
您必须将函数传递给how
参数,而不是值.我认为您可以使用匿名函数(lambda函数):
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))
示例:
>>> 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
这篇关于使用numpy百分位数对 pandas 进行重采样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文