title: Getting variable no of pandas rows w.r.t. a dictionary lookup
body: <p>In this sample dataframe df:</p>
  <pre><code>import pandas as pd
  import numpy as np
  import random, string
  
  max_rows = {'A': 3, 'B': 2, 'D': 4} # max number of rows to be extracted
  
  data_size = 1000
  
  df = pd.DataFrame({'symbol': pd.Series(random.choice(string.ascii_uppercase) for _ in range(data_size)),
                'qty': np.random.randn(data_size)}).sort_values('symbol')
  
  </code></pre>
  <p>How to get a dataframe with variable rows from a dictionary?</p>
  <p>Tried using <code>[df.groupby('symbol').head(i) for i in df.symbol.map(max_rows)]</code>. It gives a RuntimeWarning and looks very incorrect.</p>