2017-05-08 64 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

相关问题