1 回答
TA贡献1797条经验 获得超6个赞
让我们做crosstab
s = pd.crosstab(df.Client,df.Result,margins=True).drop('All')
s['Cal1']=(s['All'] - s['Dealer Reject'] - s['Dealer Timeout'])/(s['All'] - s['Customer Reject'])
s = s.stack().reset_index(name='value')
s
Client Result value
0 A Covered 1.00
1 A Customer Reject 1.00
2 A Customer Timeout 1.00
3 A Dealer Reject 0.00
4 A Dealer Timeout 0.00
5 A Done 0.00
6 A No RFQ 0.00
7 A Tied Covered 0.00
8 A Tied Done 0.00
9 A Tied Traded Away 0.00
10 A Traded Away 0.00
11 A All 3.00
12 A Cal1 1.50
13 B Covered 0.00
14 B Customer Reject 0.00
15 B Customer Timeout 0.00
16 B Dealer Reject 1.00
17 B Dealer Timeout 1.00
18 B Done 1.00
19 B No RFQ 1.00
20 B Tied Covered 1.00
21 B Tied Done 1.00
22 B Tied Traded Away 1.00
23 B Traded Away 1.00
24 B All 8.00
25 B Cal1 0.75
26 C Covered 0.00
27 C Customer Reject 0.00
28 C Customer Timeout 0.00
29 C Dealer Reject 0.00
30 C Dealer Timeout 0.00
31 C Done 0.00
32 C No RFQ 1.00
33 C Tied Covered 0.00
34 C Tied Done 0.00
35 C Tied Traded Away 0.00
36 C Traded Away 0.00
37 C All 1.00
38 C Cal1 1.00
39 D Covered 1.00
40 D Customer Reject 1.00
41 D Customer Timeout 1.00
42 D Dealer Reject 1.00
43 D Dealer Timeout 1.00
44 D Done 1.00
45 D No RFQ 1.00
46 D Tied Covered 1.00
47 D Tied Done 1.00
48 D Tied Traded Away 1.00
49 D Traded Away 1.00
50 D All 11.00
51 D Cal1 0.90
添加回答
举报