title: Resample DataFrame per night
body: <p>I have a DataFrame which marks events. 
  I need to count the number of these events per night, e.g. evening after 19:00 till morning before 08:00.</p>
  
  <p>I was thinking about using <code>count()</code>, but my difficulties are with the switch of date during the night.</p>
  
  <p>I do NOT want <code>df.resample("d").count()</code> as this will count all events per calender day, i.e. 00::00 till 24:00. I want all events from 19:00 till 08:00 on the next day.</p>
  
  <p>Here an example code that will generate between 80 and 120 events per night at random times:</p>
  
  <pre><code>np.random.seed(843)
  rand_times = []
  for i in range(5):
      rand_times.extend([datetime.datetime(2015,8,i+12,20,0,0) + pd.Timedelta(k, unit="m") for k in np.random.randint(600, size=np.random.randint(low=80, high=120))])
  rand_times.sort()
  df = pd.DataFrame(["1234"]*len(rand_times), index=rand_times, columns=["participant_ID"])
  
  df.head()
      participant_ID
  2015-08-12 20:02:00     1234
  2015-08-12 20:12:00     1234
  2015-08-12 20:15:00     1234
  2015-08-12 20:19:00     1234
  2015-08-12 20:21:00     1234
  </code></pre>
  
  <p>What I have done so far is manually access every night, by looping through them:</p>
  
  <pre><code>for i in range(5):
      print(df.loc[(df.index &gt;= datetime.datetime(2015,8,12+i,20,0,0)) &amp; (df.index &lt;= datetime.datetime(2015,8,12+i+1,8))].count())
  
  participant_ID    115
  dtype: int64
  participant_ID    90
  dtype: int64
  participant_ID    110
  dtype: int64
  participant_ID    114
  dtype: int64
  participant_ID    87
  dtype: int64
  </code></pre>
  
  <p>Is there a simpler way to do this? I will need to further process this information, count events per hour per night etc.</p>
  
  <p>Any help is appreciated!</p>