# How to sample rows from a dataframe?

**URL:** <https://discourse.julialang.org/t/how-to-sample-rows-from-a-dataframe/19782>\
**Category:** New to Julia\
**Created:** [January 18, 2019, 1:39pm UTC](https://discourse.julialang.org/t/how-to-sample-rows-from-a-dataframe/19782 "2019-01-18T13:39:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 18, 2019, 2:00pm UTC](https://discourse.julialang.org/t/how-to-sample-rows-from-a-dataframe/19782/2 "2019-01-18T14:00:10Z")

</div>

You can use `StatsBase.sample` to sample without replacement, and (optionally) keep the order:

```julia
using StatsBase, DataFrames
myDF = DataFrame(A = 1:10, B = 21:30)
myDF[sample(axes(myDF, 1), 3; replace = false, ordered = true), :]

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-sample-rows-from-a-dataframe/19782)._
