 <p>Assuming you had a CSV read into pandas:</p> <pre><code>df = pandas.read_csv("csvfile.csv") sample = df.sample(n) sample.to_csv("sample.csv") </code></pre> <p>You could make it even shorter:</p> <pre><code>df.sample(n).to_csv("csvfile.csv") </code></pre> <p>The <a href="http://pandas.pydata.org/pandas-docs/stable/io.html#io-store-in-csv" rel="nofollow">Pandas IO docs</a> have a great deal more information and options available, as does the <code>dataframe.sample</code> method.</p>