title: How to randomly select fixed number of rows (if greater) per group else select all rows in pandas?
body: <p>Example Dataframe:</p>
  <pre><code>    Name Group_Id
      AAA  1
      ABC  1
      BDF  1
      CCC  2
      XYZ  2
      DEF  3 
  </code></pre>
  <p>How could I randomly select fixed number of rows for each <code>Group_Id</code>? <a href="https://stackoverflow.com/a/46128248/10927892">This answer</a> suggests a method to use:</p>
  <pre><code>df.groupby('Group_Id').apply(lambda x: x.sample(2)).reset_index(drop=True)
  </code></pre>
  <p>But it throws an error if there is any group which has less than <code>2</code> rows. I want to be able to select all rows in that case. <code>.head()</code> allows to do that but I want random samples and not the initial rows.</p>
  <p>Say that I want max two random draws per <code>Group_Id</code>, I would get:</p>
  <pre><code>    Name Group_Id
      AAA  1
      BDF  1
      CCC  2
      XYZ  2
      DEF  3
  </code></pre>