title: How to group dataframe by hour using timestamp with Pandas
body: <p>I have the following dataframe structure that is indexed with a timestamp:</p>
  
  <pre><code>    neg neu norm    pol pos date
  time                        
  1520353341  0.000   1.000   0.0000  0.000000    0.000   
  1520353342  0.121   0.879   -0.2960 0.347851    0.000   
  1520353342  0.217   0.783   -0.6124 0.465833    0.000   
  </code></pre>
  
  <p>I create a date from the timestamp:</p>
  
  <pre><code>data_frame['date'] = [datetime.datetime.fromtimestamp(d) for d in data_frame.time]
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>    neg neu norm    pol pos date
  time                        
  1520353341  0.000   1.000   0.0000  0.000000    0.000   2018-03-06 10:22:21
  1520353342  0.121   0.879   -0.2960 0.347851    0.000   2018-03-06 10:22:22
  1520353342  0.217   0.783   -0.6124 0.465833    0.000   2018-03-06 10:22:22
  </code></pre>
  
  <p>I want to <strong>group by hour</strong>, while getting the <strong>mean</strong> for <strong>all the values, except the timestamp</strong>, that should be the hour from where the group started. So <strong>this is the result I want to archive:</strong></p>
  
  <pre><code>    neg neu norm    pol pos
  time                    
  1520352000  0.027989    0.893233    0.122535    0.221079    0.078779
  1520355600  0.028861    0.899321    0.103698    0.209353    0.071811
  </code></pre>
  
  <p>The closest I have gotten so far has been with this <a href="https://stackoverflow.com/questions/11391969/how-to-group-pandas-dataframe-entries-by-date-in-a-non-unique-column">answer</a>: </p>
  
  <pre><code>data = data.groupby(data.date.dt.hour).mean()
  </code></pre>
  
  <p><strong>Results:</strong></p>
  
  <pre><code>    neg neu norm    pol pos
  date                    
  0   0.027989    0.893233    0.122535    0.221079    0.078779
  1   0.028861    0.899321    0.103698    0.209353    0.071811
  </code></pre>
  
  <p>But I cant figure out how to keep the timestamp that takes in account he hour where the grouby started. </p>