title: Find the number of customers waiting
body: <p><code>df</code> is a pandas dataframe which contains the customer data for a retail shop. The key columns in <code>df</code> are <code>customer_arrival_time</code> and <code>service_completion_time</code>. A small sample is given below:</p>
  <pre><code>df = pd.DataFrame([[2019-12-16 12:30, 2019-12-16 13:28], [2019-12-16 12:48, 2019-12-16 13:15], [2019-12-16 13:00, 2019-12-16 13:30]], columns=['customer_arrival_time', 'service_completion_time'])
  </code></pre>
  <p>I am trying to calculate the queue length at the time of each customer arrival using the following code:</p>
  <pre><code>df['current_queue_length'] = 0
  for index_1 in (0, len(df)):
      count = 0
      for index_2 in (0, len(df)):
          if df['customer_arrival_time'][index_1]&gt;df['customer_arrival_time'][index_2] and df['customer_arrival_time'][index_1]&lt;df['service_completion_time'][index_2]:
              count = count+1
      df['current_queue_length'][index_1] = count
  </code></pre>
  <p>The new column results for the given example should be: <code>[0 1 2]</code></p>
  <p>However, the code is running for a very long time without completion, possibly due to the large dataset (approx 100,000 customer arrivals). Is there a more efficient way to obtain the desired values?</p>
  <p>Note: I have also sorted the data based on the arrival times. Can I somehow use this feature for additional advantage?</p>