title: pandas Normalize dataframe to data (quotes) at specific time (not midnight)
body: <p>I have daily data in a dataframe (ds) that looks like this spanning several years:</p>
  
  <p><img src="https://i.stack.imgur.com/PmCj3.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/x6Hy7.png" alt="enter image description here"></p>
  
  <p>For each day, I need all of the quotes normalized to a specific time's of that particular day. For example, on June 1st, I need all the quotes normalized to the quote at 3pm June 1st, but on June 2nd, I need them all normalized to the quote at 3pm of June 2nd.</p>
  
  <p>I have a dataframe of all the 3pm quotes daily, as shown here:</p>
  
  <p><img src="https://i.stack.imgur.com/xtg7a.png" alt="enter image description here"></p>
  
  <p>So I thought it would work if I could simply divide my quotes dataframe (ds) by the 3pm dataframe:</p>
  
  <pre><code>dr = ds.groupby(ds.index.date).apply(lambda x: x / b)
  </code></pre>
  
  <p><strong>Of note, the 3pm dataframe includes <em>more</em> days than the quotes dataframe (ds).</strong> As a result, the quotes dataframe would have to divide through the correct respective days in the 3pm dataframe, probably using something like <code>b.index.date</code></p>
  
  <p>I've also tried not using a separate dataframe, and instead pulling out the last available quote from the quote dataframe (ds) itself - this did not work either:</p>
  
  <p><img src="https://i.stack.imgur.com/j8C59.png" alt="enter image description here"></p>
  
  <p>EDIT: Thanks for the advice DSM. Does this help at all? Not sure if I should pd.to_string() the dataframe because that doesn't seem easily clipboard-readable either.</p>
  
  <p><strong>Quotes ds dataframe:</strong></p>
  
  <pre><code>bid ask mid
  2000-01-04 14:45:12+00:00   281.0   281.5   281.25
  2000-01-04 14:46:10+00:00   281.0   282.0   281.5
  2000-01-04 14:47:14+00:00   281.2   282.2   281.7
  2000-01-04 14:47:22+00:00   281.25  281.85  281.55
  2000-01-04 14:47:47+00:00   281.25  281.75  281.5
  2000-01-04 14:48:09+00:00   281.4   281.9   281.65
  2000-01-04 14:48:40+00:00   281.3   282.3   281.8
  2000-01-04 14:49:40+00:00   281.3   281.8   281.55
  2000-01-04 14:49:45+00:00   281.2   282.2   281.7
  2000-01-04 14:50:53+00:00   281.4   281.9   281.65
  </code></pre>
  
  <p><strong>3pm dataframe:</strong></p>
  
  <pre><code>bid_close   ask_close   price
  2000-01-04 15:00:00+00:00   281.35  281.95  281.65
  2000-01-05 15:00:00+00:00   280.73  281.48  281.105
  2000-01-06 15:00:00+00:00   279.7   280.3   280.0
  2000-01-07 15:00:00+00:00   282.3   282.9   282.6
  2000-01-10 15:00:00+00:00   281.7   282.3   282.0
  2000-01-11 15:00:00+00:00   282.1   282.7   282.4
  2000-01-12 15:00:00+00:00   281.9   282.5   282.2
  2000-01-13 15:00:00+00:00   281.9   282.7   282.3
  2000-01-14 15:00:00+00:00   283.15  283.75  283.45
  2000-01-17 15:00:00+00:00   285.5   286.0   285.75
  </code></pre>
  
  <p>And the command:</p>
  
  <pre><code>c = ds.groupby(ds.index.date).apply(lambda x: x / x.between_time('14:30:00', '14:59:59').resample('30Min', how='last').dropna(how='all'))
  </code></pre>
  
  <p>I've also tried (which seems close):</p>
  
  <pre><code>df = a.groupby(a.index.date).apply(lambda x: x / x.between_time('14:45:00', '14:59:59').tail(1))
  </code></pre>
  
  <p>Here's a link that seems related (and what I based the command above off of): <a href="https://stackoverflow.com/questions/18677271/grouping-daily-data-by-month-in-python-pandas-and-then-normalising">Grouping daily data by month in python/pandas and then normalizing</a></p>