per_of_runs_all_bowl
是一个看起来像这样的系列;
Abdur Razzak 44.915254
Ajit Agarkar 31.250000
Albie Morkel 41.538462
Alok Kapali 16.666667
Andre Nel 50.000000
Andrew Flintoff 43.636364
Andrew Symonds 20.833333
Brad Hodge 41.666667
Brett Lee 42.763158
Chamara Silva 41.666667
Chaminda Vaas 49.541284
Chamu Chibhabha 44.736842
Chris Gayle 25.000000
Chris Martin 50.000000
Chris Schofield 38.461538
...
data1.groupby(['bowler']).size()
看起来像这样;
Abdur Razzak 118
Ajit Agarkar 48
Albie Morkel 65
Alok Kapali 12
Andre Nel 24
Andrew Flintoff 110
Andrew Symonds 72
Brad Hodge 12
Brett Lee 152
Chamara Silva 12
Chaminda Vaas 109
Chamu Chibhabha 38
Chris Gayle 24
Chris Martin 92
Chris Schofield 78
...
per_of_runs_all_bowl.loc[(data1.groupby(['bowler']).size() > 60)]
会返回.size()
大于60的“运行百分比”..就像这样;
Abdur Razzak 44.915254
Albie Morkel 41.538462
Andrew Flintoff 43.636364
Andrew Symonds 20.833333
Brett Lee 42.763158
Chaminda Vaas 49.541284
Chris Martin 50.000000
Chris Schofield 38.461538
Daniel Vettori 42.758621
Dilhara Fernando 61.467890
Dimitri Mascarenhas 30.952381
Gayan Wijekoon 25.000000
Harbhajan Singh 32.394366
Irfan Pathan 45.652174
Jacob Oram 23.750000
James Anderson 48.484848
...
如何获得返回的“运行百分比”以及这样的大小?
Abdur Razzak 44.915254 118
Albie Morkel 41.538462 65
Andrew Flintoff 43.636364 110
Andrew Symonds 20.833333 72
Brett Lee 42.763158 152
答案 0 :(得分:0)
除此之外,我无法想到任何其他事情;
我已经创建了一个新的DataFrame;
new_df = pd.DataFrame({'size':data1.groupby(['bowler']).size(),'per':list(per_of_runs_all_bowl.values)})
然后根据大小进行过滤;
new_df_fil = new_df[new_df['size'] > 60]
per size
bowler
Abdur Razzak 4.237288 118
Albie Morkel 9.230769 65
Andrew Flintoff 8.181818 110
Andrew Symonds 15.277778 72
Brett Lee 10.526316 152
但这有效吗?我确定必须有'pythonic' &安培; '熊猫-IC'做到这一点的方法!
答案 1 :(得分:0)
试试这个:
df = pd.DataFrame({'size': data1.groupby(['bowler']).size(), 'percent of runs':per_of_runs_all_bowl})
df[df['size'] > 60]
这个解决方案效率很高。