2017-05-08 67 views
-4

我有以下代碼:大熊貓返回對象類型而不是值

import pandas as pd 
df=pd.read_csv('Fortigate-Inbound traffic from blacklisted IP.csv') 
df2= df[df['Device Action']=='Accept'] 
df3 = df2.groupby(['Destination Address', 'Sum(Aggregated Event Count)']) 
print(df3) 

其中在數據幀在0x0000016F627C3208返回pandas.core.groupby.DataFrameGroupBy對象,而不是實際值。我怎樣才能打印這些值?

+4

你會從閱讀有關大熊貓的文檔中受益。 –

+2

這是打印一個* groupby對象*,這正是你告訴它做的。 –

+0

你只是想看看小組,或者你想做一些聚合(每個組的列的總和,每個組的列的大小等) – ayhan

回答

0

我想你需要通過aggregationsum

df3 = df2.groupby('Destination Address', as_index=False)['Aggregated Event Count'].sum() 

樣品:

df2 = pd.DataFrame({'Destination Address':['a','a','a', 'b'], 
        'Aggregated Event Count':[1,2,3,4]}) 
print (df2) 
    Aggregated Event Count Destination Address 
0      1     a 
1      2     a 
2      3     a 
3      4     b 

df3 = df2.groupby('Destination Address', as_index=False)['Aggregated Event Count'].sum() 
print (df3) 
    Destination Address Aggregated Event Count 
0     a      6 
1     b      4 

另一種解決方案:

df3 = df2.groupby('Destination Address')['Aggregated Event Count'].sum().reset_index() 
print (df3) 
    Destination Address Aggregated Event Count 
0     a      6 
1     b      4 
+0

謝謝,這有幫助! – Mohnish

相關問題