title: How to aggregate values of a Dataframe by mean in Python?
body: <p>I have the following dataframe consisting of the number of posts made by a user in a duration of 2 weeks (days from -7 to 7). I want to create another dataframe that should have the mean number of posts made per day. I have written the following code but it returns me a series with 1 column instead of a Dataframe. The required Dataframe should have 2 separate columns for <code>day</code> and <code>mean</code>.</p>
  <p><strong>Part of Dataframe (df)</strong></p>
  <pre><code>UserId          Date                -7  -6  -5  -4  -3  -2  -1  0   1   2   3   4   5   6   7
  87      2011-05-10 18:38:55.030     0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
  487     2011-11-29 14:46:12.080     0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
  21      2012-03-02 14:35:06.867     0   1   0   1   2   0   2   2   0   1   2   2   1   3   1
  </code></pre>
  <p><strong>CODE (To obtain mean posts per day)</strong></p>
  <pre><code>df.iloc[:,2:].mean()
  </code></pre>
  <p><strong>Code Output</strong></p>
  <pre><code>-7  0
  -6  0.33
  -5  0.33
  -4  0.33
  -3  0.66
  -2  0
  -1  1
  0   0.66
  1   0
  2   0.33
  3   0.66
  4   0.66
  5   0.33
  6   1
  7   0.33
  </code></pre>
  <p>This output is correct, the only problem is that it is a series. The expected output should have 2 separate columns for <code>day</code> and <code>mean</code> as shown.</p>
  <p><strong>Expected Output</strong></p>
  <pre><code>day mean
  -7  0
  -6  0.33
  -5  0.33
  -4  0.33
  -3  0.66
  -2  0
  -1  1
  0   0.66
  1   0
  2   0.33
  3   0.66
  4   0.66
  5   0.33
  6   1
  7   0.33
  </code></pre>