Pandas random sample with remove
<p>I'm aware of <code>DataFrame.sample()</code>, but how can I do this and also remove the sample from the dataset? (<em>Note: AFAIK this has nothing to do with sampling with replacement</em>)</p>

<p>For example here is <strong>the essence</strong> of what I want to achieve, this does not actually work:</p>

<pre><code>len(df) # 1000

df_subset = df.sample(300)
len(df_subset) # 300

df = df.remove(df_subset)
len(df) # 700
</code></pre>

<p>If your index is unique</p>

<pre><code>df = df.drop(df_subset.index)
</code></pre>

<hr>

<p><strong><em>example</em></strong></p>

<pre><code>df = pd.DataFrame(np.arange(10).reshape(-1, 2))
</code></pre>

<hr>

<p><strong><em>sample</em></strong></p>

<pre><code>df_subset = df.sample(2)
df_subset
</code></pre>

<p><a href="http://i.stack.imgur.com/9iD0E.png" rel="nofollow"><img src="http://i.stack.imgur.com/9iD0E.png" alt="enter image description here"></a></p>

<hr>

<p><strong><em>drop</em></strong></p>

<pre><code>df.drop(df_subset.index)
</code></pre>

<p><a href="http://i.stack.imgur.com/4TU49.png" rel="nofollow"><img src="http://i.stack.imgur.com/4TU49.png" alt="enter image description here"></a></p>

python pandas