熊猫Pivot_table自定义Aggfunc

时间:2018-07-13 14:12:19

标签: python pandas pivot-table

数据透视表如何评估我创建的功能?

它是否一次传递所有值,并且只返回.25和.75分位数之间的值?还是一次评估每个值并确定其是否适合.25和.75分位数?

def Mean_Outliers_Removed(values):
   mid_quantiles = values.quantile([.25, .75])
   return np.mean(mid_quantiles)


pivotall= pd.pivot_table(dftat,index=['Service','Month','1 Type','2 Type' ], 
           values=['1 TAT mins', '2 TAT mins'],aggfunc=[np.mean,Mean_Outliers_Removed,
                                                       np.std,len],margins=True)

谢谢。

edit
1 TAT mins  1 Type  2 Type  2 TAT mins  Service Month
31479.6 OP  NAP 31405.8 RAD Jun-18
18561   OP  RAD 18576   RAD Jun-18
18507   OP  RAD 18727.8 RAD Jun-18
18429   OP  SP  18427.8 RAD Jun-18
18315   INP SP  18408   RAD Jun-18
17835.6 OP  SP  17835   RAD Jun-18
17736   OP  SP  17734.8 RAD Jun-18
17517   OP  RAD 17611.8 RAD Jun-18
17115.6 INP US  17815.8 CARD    Jun-18
13149.6 OP  RAD 13279.8 RAD Jun-18
13146   OP  SP  13144.8 RAD Jun-18
11500.8 OP  RAD 11500.8 RAD Jun-18
11116.8 OP  RAD 11293.8 RAD Jun-18
10966.8 OP  SP  10966.8 RAD Jun-18
10419.6 OP  NAL 10419   RAD Jun-18
10288.8 OP  XT  10287.6 RAD Jun-18
10252.8 OP  XT  10251.6 RAD Jun-18
10018.8 OP  RAN 10018.8 RAD Jun-18
9849    OP  RAN 9847.8  RAD Jun-18
9687    OP  RAN 9727.8  RAD Jun-18
8538.6  INP SP  10282.8 CARD    Jun-18
8199.6  OP  SP  8199    RAD Jun-18

0 个答案:

没有答案