2016-01-28 79 views
-1
df=pandas.DataFrame(processed_data_format, columns=["file_name", "innings", "over","ball", "individual ball", "runs","batsman", "wicket_status","bowler_name","fielder_name"]) 
df.groupby(['batsman'])['runs','ball'].sum() 

一個GROUPBY利用這一點,我會得到這樣的如何使用SUM()和COUNT()(兩者)在大熊貓

a 30 29 
b 4 1 
c 10 15 

的結果,我想獲得的計數如所提到的名爲filename與代碼的結果列above.The最終結果應該是像

a 30 29 2 
b 4 1 1 
c 10 15 2 
+0

您可以添加樣本'processed_data_format' – jezrael

+0

http://stackoverflow.com/questions/29127376/pandas-using-multiple - 功能在一個組中可能的重複,更不用說這裏完全覆蓋http://pandas.pydata.org/pandas-docs/stable/groupby.html#applying-multiple-functions-at-once – Chris

+0

@ jezrael processed_data_format是列表的列表,沒有任何默認列,這就是爲什麼我給每個列的名稱。processed_data_format看起來像[[102032,1,1,1,3,4,Sachin,Caught,Akthar,Malik ],[102032,1,1,1,0.3,4,Sachin,Caught,Akthar,Malik] .....................] –

回答

0
df=pandas.DataFrame(processed_data_format, columns=["file_name", "innings", "over","ball", "individual ball", "runs","batsman", "wicket_status","bowler_name","fielder_name"])  
a = {'runs':['sum'],'ball':['sum'],'file_name':['nunique']} 
t = df.groupby('batsman').agg(a) 

ñ o需要使用count()而不是count使用nunique來獲取唯一值的數量