title: Pandas: using groupby to make a table
body: <p>I have dataframe</p>
  
  <pre><code>i,Unnamed: 0,ID,active_seconds,subdomain,search_term,period,code,buy    
  0,56574,08cd0141663315ce71e0121e3cd8d91f,6,market.yandex.ru,None,515,100.0,1.0  
  1,56576,08cd0141663315ce71e0121e3cd8d91f,26,market.yandex.ru,None,515,100.0,1.0 
  2,56578,08cd0141663315ce71e0121e3cd8d91f,14,market.yandex.ru,None,515,100.0,1.0 
  3,56579,08cd0141663315ce71e0121e3cd8d91f,2,market.yandex.ru,None,515,100.0,1.0  
  4,56581,08cd0141663315ce71e0121e3cd8d91f,8,market.yandex.ru,None,515,100.0,1.0  
  5,56582,08cd0141663315ce71e0121e3cd8d91f,32,market.yandex.ru,None,515,100.0,1.0 
  6,56583,08cd0141663315ce71e0121e3cd8d91f,16,market.yandex.ru,None,515,100.0,1.0 
  7,56584,08cd0141663315ce71e0121e3cd8d91f,4,market.yandex.ru,None,515,100.0,1.0  
  8,56585,08cd0141663315ce71e0121e3cd8d91f,10,market.yandex.ru,None,515,100.0,1.0 
  9,56639,08cd0141663315ce71e0121e3cd8d91f,2,market.yandex.ru,None,516,100.0,1.0  
  </code></pre>
  
  <p>I want to get table with sum of <code>active_seconds</code> and quantity of <code>period</code>(One number is a One period). In this case I want to get quantity of periods =  <code>2</code> to this ID.
  I use</p>
  
  <pre><code>df.groupby(['ID', 'buy']).agg({'period': len, 'active_seconds': sum}).rename(columns={'active_seconds': 'count_sec', 'period': 'sum_session'}).reset_index()
  </code></pre>
  
  <p>But it return uncorrectly value to quantity of periods. How can I fix that?</p>