# Row index in a dataframe

**URL:** <https://discourse.julialang.org/t/row-index-in-a-dataframe/70265>\
**Category:** General Usage\
**Tags:** question, dataframes\
**Created:** [October 23, 2021, 2:59pm UTC](https://discourse.julialang.org/t/row-index-in-a-dataframe/70265 "2021-10-23T14:59:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![corny85](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@corny85](https://discourse.julialang.org/u/corny85)\
**Post date:** [October 23, 2021, 2:59pm UTC](https://discourse.julialang.org/t/row-index-in-a-dataframe/70265/1 "2021-10-23T14:59:23Z")

</div>

Hello,

I have a dataframe that i sorted in order to get the maximum (of values in a column).  
Now, i want to get the index corresponding to this maximum in the initial dataframe.  
I’ve tried a lot of things with rownumber or other but nothing works.  
Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [October 23, 2021, 3:04pm UTC](https://discourse.julialang.org/t/row-index-in-a-dataframe/70265/2 "2021-10-23T15:04:34Z")

</div>

There is no row index in DataFrames.

Here’s something you can do though

```julia
julia> df = DataFrame(x = rand(10),y = rand(10))
10×2 DataFrame
 Row │ x y        
     │ Float64 Float64  
─────┼────────────────────
   1 │ 0.341501 0.914511
   2 │ 0.717087 0.28765
   3 │ 0.403885 0.173076
   4 │ 0.931974 0.269083
   5 │ 0.794214 0.795277
   6 │ 0.930986 0.2953
   7 │ 0.32153 0.315169
   8 │ 0.572526 0.641704
   9 │ 0.752558 0.738108
  10 │ 0.643852 0.992788

julia> rownum = findfirst(==(maximum(df.x)), df.x)
4

```

---

<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:** [October 23, 2021, 3:26pm UTC](https://discourse.julialang.org/t/row-index-in-a-dataframe/70265/3 "2021-10-23T15:26:00Z")

</div>

Alternatively you can just add a column that will serve as a row index if you prefer.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 23, 2021, 4:11pm UTC](https://discourse.julialang.org/t/row-index-in-a-dataframe/70265/4 "2021-10-23T16:11:42Z")

</div>

Just in case, the `findmax()` and `sortperm()` functions are quite useful too:

```julia
df = DataFrame(x = rand(10), y = rand(10))
findmax(df.x) # outputs the maximum x-value and its row number
ix = sortperm(df.x, rev=true)
ix[1] # row number with maximum x value
df.x[ix[1]] # maximum value in column x

```

---

<div class="post-metadata">

**Author:** ![corny85](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@corny85](https://discourse.julialang.org/u/corny85)\
**Post date:** [October 23, 2021, 5:55pm UTC](https://discourse.julialang.org/t/row-index-in-a-dataframe/70265/5 "2021-10-23T17:55:09Z")

</div>

Thanks a lot !
