# How to keep only first 20 rows in DataFrame?

**URL:** https://discourse.julialang.org/t/how-to-keep-only-first-20-rows-in-dataframe/67206
**Category:** Data
**Tags:** question, dataframes
**Created:** [August 28, 2021, 6:12am UTC](https://discourse.julialang.org/t/how-to-keep-only-first-20-rows-in-dataframe/67206 "2021-08-28T06:12:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![wakimchris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wakimchris/32/21325_2.png) [@wakimchris](https://discourse.julialang.org/u/wakimchris)
#### Post date: [August 28, 2021, 6:12am UTC](https://discourse.julialang.org/t/how-to-keep-only-first-20-rows-in-dataframe/67206/1 "2021-08-28T06:12:42Z")

</div>

How do I keep only first 20 rows in a DataFrame and export it to a new DataFrame variable? in one line

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [August 28, 2021, 6:13am UTC](https://discourse.julialang.org/t/how-to-keep-only-first-20-rows-in-dataframe/67206/2 "2021-08-28T06:13:56Z")

</div>

- `first(df, 20)` if you want to produce 20 or less rows (if data frame is shorter).
- `df[1:20, :]` if you want to produce 20 rows or throw error if data frame is shorter.
