title: Pandas DataFrame.groupby including index
body: <p>I have a dataset taken from the Windows Eventlog. The <code>TimeGenerated</code> column is set as the index. I'd like to get an aggregated view showing me the number of events, by <code>EventType</code> (info/warn/err) and by the index value. I could use <code>resample()</code> to set the datetime resolution (day, business day, etc).</p>
  
  <p>Here's my DataFrame:</p>
  
  <p><a href="https://i.stack.imgur.com/fQRCr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fQRCr.png" alt="DataFrame"></a></p>
  
  <pre><code>log.info()
  
  &lt;class 'pandas.core.frame.DataFrame'&gt;
  DatetimeIndex: 80372 entries, 2015-08-31 12:15:23 to 2015-05-11 04:08:07
  Data columns (total 4 columns):
  EventID          80372 non-null int64
  SourceName       80372 non-null object
  EventType        76878 non-null object
  EventCategory    80372 non-null int64
  dtypes: int64(2), object(2)
  memory usage: 3.1+ MB
  </code></pre>
  
  <p>I can of course group by the EventType, but this drops my index:</p>
  
  <pre><code>log[['EventID', 'EventType']].groupby('EventType').count('EventID')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0L4vu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0L4vu.png" alt="Grouped"></a></p>
  
  <p>I would have to specify my existing index it in the call to <code>groupby()</code>, but how can I reference the index? Or do I have to perform a <code>reset_index()</code> before the <code>groupby()</code> call? Or am I simply going about this all wrong and is it painfully obvious that I'm a Pandas newbie? ;-)</p>
  
  <p>Version info:</p>
  
  <ul>
  <li>Python 3.4.2</li>
  <li>pandas 0.16.2</li>
  <li>numpy 1.9.2</li>
  </ul>
  
  <h1>Update</h1>
  
  <p>To clarify further, what I'd like to achieve is:</p>
  
  <ul>
  <li>A count of the EventIDs (the number of events)</li>
  <li>By EventType (in axis 1)</li>
  <li>By Timestamp (in axis 0)</li>
  </ul>
  
  <p>Note that the Timestamp is not unique (in the raw DF), as multiple events can occur simultaneously.</p>
  
  <p>One way I've been able to achieve what I wanted, is by doing:</p>
  
  <pre><code>temp = log.reset_index()
  temp.groupby(['TimeGenerated','EventType']).count('EventID'['EventID'].unstack().fillna(0)
  </code></pre>
  
  <p>In that case, my output is:</p>
  
  <p><a href="https://i.stack.imgur.com/9MXm8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9MXm8.png" alt="Grouped 2"></a></p>
  
  <p>Which then allows me to resample the count further, e.g. :</p>
  
  <pre><code>temp.resample('MS', how='sum')
  </code></pre>
  
  <p>This works, but what I don't know if whether having to perform a <code>reset_index()</code> is necessary to achieve this grouping. Could I have done it in a better (read: more efficient) way?</p>