title: How to detect rectangle in a rectangle?
body: <p>I am having the co-ordinates of top-left corner and the bottom-right corner of a list of rectangles say (a,b) and (c,d). I want to detect and remove rectangles which are within a rectangle. Overlapping rectangles can stay.</p>
  
  <p>I have a dataset of 10,000 rectangles and I want an efficient way to solve this problem.</p>
  
  <p>Currently I am doing it this way,</p>
  
  <pre><code>import pandas
  
  data = pd.read_csv('dataset.csv')
  
  l = list(range(len(data)-1))
  
  for i in range(len(data)):
      length = len(l)
      if i &gt;= length:
          break
      for j in range(i+1, length):
          if j &gt;= len(l):
             break
          if (data.iloc[l[i]]['a'] &gt;= data.iloc[l[j]]['a']) and (data.iloc[l[i]]['b'] &lt;= data.iloc[l[j]]['b']) and (data.iloc[l[i]]['c'] &lt;= data.iloc[l[j]]['c']) and (data.iloc[l[i]]['d'] &gt;= data.iloc[l[j]]['d']):
             l.pop(j)
  </code></pre>
  
  <p>I have implemented this algorithm after sorting the dataset in descending order of the area of the rectangles as rectangles with bigger areas do not fit inside rectangles with smaller areas. Here, I am poping the index of the rectangle from the list l after detecting whether it is inside another rectangle. Each time an element is poped it reduces the iterations.</p>
  
  <p>This is taking few hours to solve and I need an efficient way to solve it even for hundred thousand samples.</p>
  
  <p>Please help!</p>