Sampling in pandas
<p>If I want to randomly sample a pandas dataframe I can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sample.html" rel="nofollow">pandas.DataFrame.sample</a>.</p>

<p>Suppose I randomly sample 80% of the rows. How do I automatically get the other 20% of the rows that were not picked?</p>

<p>As Lagerbaer explains, one can add a column with a unique index to the dataframe, or randomly shuffle the entire dataframe. For the latter, </p>

<pre><code>df.reindex(np.random.permutation(df.index))
</code></pre>

<p>works. (np means numpy)</p>

python pandas