【发布时间】:2014-12-04 19:20:25
【问题描述】:
是否可以在 pandas 数据透视表中使用百分位数或分位数作为 aggfunc?我试过 numpy.percentile 和 pandas quantile 都没有成功。
【问题讨论】:
是否可以在 pandas 数据透视表中使用百分位数或分位数作为 aggfunc?我试过 numpy.percentile 和 pandas quantile 都没有成功。
【问题讨论】:
虚拟数据:
In [135]: df = pd.DataFrame([['a',2,3],
['a',5,6],
['a',7,8],
['b',9,10],
['b',11,12],
['b',13,14]], columns=list('abc'))
np.percentile 似乎可以正常工作?
In [140]: df.pivot_table(columns='a', aggfunc=lambda x: np.percentile(x, 50))
Out[140]:
a a b
b 5 11
c 6 12
【讨论】:
0.18.0 中被破坏,但在 0.18.1 中被修复。