title: Stratified Sampling in Pandas
body: <p>I've looked at the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html" rel="noreferrer">Sklearn stratified sampling docs</a> as well as the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sample.html" rel="noreferrer">pandas docs</a> and also <a href="https://stackoverflow.com/questions/41035187/stratified-samples-from-pandas">Stratified samples from Pandas</a> and <a href="https://stackoverflow.com/questions/36997619/sklearn-stratified-sampling-based-on-a-column">sklearn stratified sampling based on a column</a> but they do not address this issue.</p>
  
  <p>Im looking for a fast pandas/sklearn/numpy way to generate stratified samples of size n from a dataset. However, for rows with less than the specified sampling number, it should take all of the entries.</p>
  
  <p>Concrete example:</p>
  
  <p><a href="https://i.stack.imgur.com/Y1EsP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Y1EsP.png" alt="enter image description here"></a></p>
  
  <p>Thank you! :)</p>