# I might have missed this but why is \`head(df::AbstractDataFrame)\` deprecated?

**URL:** <https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988>\
**Category:** Data\
**Created:** [August 26, 2019, 7:42am UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988 "2019-08-26T07:42:53Z")\
**Posts on this page:** 20\
**Page:** 2

<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 26, 2019, 1:48pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/21 "2019-08-26T13:48:48Z")

</div>

> [@nalimilan](#):
>
> Come on, this change has been released months ago without anybody complaining, and suddenly it’s a major blocker?

I do not think it is a major blocker 😄. I think of it as one of these things that are on the border of my personal preference and I acknowledge that people might have diverging opinion on it (that is why when you proposed deprecating it I was OK with this, as you had “big pro deprecation” opinion while I had “very small con deprecation” opinion).

This issue is really minor (but I am OK to discuss it if people want). Compare this to conflicting opinions how plotting should be implemented 😄.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 26, 2019, 1:56pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/22 "2019-08-26T13:56:11Z")

</div>

> [@nalimilan](#):
>
> this change has been released months ago without anybody complaining, and suddenly it’s a major blocker?

No, it’s just a little annoying in day-to-day use.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [August 26, 2019, 2:21pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/23 "2019-08-26T14:21:43Z")

</div>

I don’t understand why one would prefer legacy over generality. If there are existing functions that are used all over `Base` or other packages that make perfect sense in the context of a dataframe, why prefer different names? Just because they are legacy from pandas or R? I could see an argument for the DataFrames use of `first` not being the same as in `Base`, but for example why not prefer `size(df,1)` over `nrows(df)` when `size` has a perfectly universal meaning in Julia, is it really that much more typing? I feel like nobody would ask for `nrows` for an array.

---

<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 26, 2019, 2:28pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/24 "2019-08-26T14:28:34Z")

</div>

I think your example shows well why people might have different opinions about those (and it is IMO OK to differ).

Consider this comparison:

```julia
julia> using DataFrames

julia> x = rand(2,2)
2×2 Array{Float64,2}:
 0.127077 0.660575
 0.915064 0.8524

julia> df = DataFrame(x)
2×2 DataFrame
│ Row │ x1 │ x2 │
│ │ Float64 │ Float64 │
├─────┼──────────┼──────────┤
│ 1 │ 0.127077 │ 0.660575 │
│ 2 │ 0.915064 │ 0.8524 │

julia> size(x)
(2, 2)

julia> size(df)
(2, 2)

julia> first(x)
0.12707672347662347

julia> first(df)
DataFrameRow
│ Row │ x1 │ x2 │
│ │ Float64 │ Float64 │
├─────┼──────────┼──────────┤
│ 1 │ 0.127077 │ 0.660575 │

```

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [August 26, 2019, 2:30pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/25 "2019-08-26T14:30:23Z")

</div>

That’s a really good argument for `first`, it doesn’t seem to be a good argument for `nrow` or `ncol`.

---

<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:** [August 26, 2019, 3:17pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/26 "2019-08-26T15:17:32Z")

</div>

FWIW, I think that

1. `first` is a bad pun here: `DataFrame`s _per se_ are not iterable (one has to go through the Tables.jl interface to get a row iterator),

2. it is not really a good idea to combine the extraction of the first row (a `DataFrameRow`) and the first `n` rows (a `DataFrame`) in a single interface function; that’s like a function sometimes returning a matrix, sometimes a vector,

3. one should not necessarily introduce a function for either of these, but think about the purpose: the user usually just wants a preview of the dataframe without looking at the whole thing; so just make `Base.show` print the first and last 10-10 rows or so (currently I think it is 20-20). For the rest, there are the shiny new `Base.getindex` accessors.

That said, I think these things are the decision of the package maintainers, and the best place to discuss them is in issues. It is great to solicit input from users, but interfaces need a single architect, or possibly a small team of 2-3 individuals, but not more.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 26, 2019, 3:25pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/27 "2019-08-26T15:25:00Z")

</div>

> [@Tamas\_Papp](#):
>
> `DataFrame` s _per se_ are not iterable

Exactly!

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [August 26, 2019, 3:37pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/28 "2019-08-26T15:37:36Z")

</div>

head, nrow and other single-argument functions are more convenient for interactive use:  
`DataFrame(...) |> ... some processing ... |> head`  
vs  
`DataFrame(...) |> ... some processing ... |> x->first(x, 5)`

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [August 26, 2019, 3:48pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/29 "2019-08-26T15:48:18Z")

</div>

You can write the latter a bit more concise with [Query.jl](https://github.com/queryverse/Query.jl):

```julia
DataFrame(...) |> ... some processing ... |> @take(5)

```

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 26, 2019, 3:48pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/30 "2019-08-26T15:48:23Z")

</div>

> [@Tamas\_Papp](#):
>
> `DataFrame`s _per se_ are not iterable

In terms of “conceptual purity”, I agree that, if one needs `eachrow` to iterate rows, then getting the first row should be `first(eachrow(df))` or `df[1, :]` (esp. since it seems DataFrames are a 2D container in that you need to indices to get a value, unlike for example IndexedTables). Why not simply `df[1:6, :]` to get the first few rows?

---

<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:** [August 26, 2019, 3:56pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/31 "2019-08-26T15:56:41Z")

</div>

> [@piever](#):
>
> Why not simply `df[1:6, :]` to get the first few rows?

I agree, but I still wonder what the use case is. In R, assignments do not print, and values print in full, so

```R
> df <- data.frame(x = 1:100, y = 101:200)
> head(df)
  x y
1 1 101
2 2 102
3 3 103
4 4 104
5 5 105
6 6 106
> df # and this prints 100 lines, not included

```

and `head` makes sense. But in Julia we can just make `Base.show` show a couple of rows from the beginning and the end (this is what is currently done, I would show fewer rows).

What’s the use case from `head` (or `first(..., n)`) when we have this?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 26, 2019, 4:36pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/32 "2019-08-26T16:36:09Z")

</div>

Good point. I admit my use can can be reduced to the number of rows being printed in jupiter being too many

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [August 26, 2019, 7:25pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/33 "2019-08-26T19:25:20Z")

</div>

> [@mkborregaard](#):
>
> I admit my use can can be reduced to the number of rows being printed in jupiter being too many

PrettyTables.jl is awesome here (requires one line of setup, but then `@pt df`)

---

<div class="post-metadata">

**Author:** ![alejandromerchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alejandromerchan/32/10500_2.png) [@alejandromerchan](https://discourse.julialang.org/u/alejandromerchan)\
**Post date:** [August 26, 2019, 7:31pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/34 "2019-08-26T19:31:44Z")

</div>

I do agree that this is a printing issue rather than a function issue. R just spits a lot of data when printing a df and you do need `head` and `tail` to make sense of large dataframes. Those functions can be replaced with a nicer output, that does not overwhelm the REPL and allows a quick glance at the df to make sure things worked as expected. I understand a lot of us have a lot of “ticks” and muscle memory patterns coming from R, but when I thought about some of the desing choices in R, they really don’t make much sense, while most of them do in Julia.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 26, 2019, 7:36pm UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/35 "2019-08-26T19:36:32Z")

</div>

OK, I’m starting to change my mind about this - I now agree with @Tamas_Papp here [I might have missed this but why is `head(df::AbstractDataFrame)` deprecated? - #26 by Tamas\_Papp](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/26)

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [May 12, 2021, 3:51am UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/36 "2021-05-12T03:51:02Z")

</div>

Have you considered making a small package `DataFramesExtra` in which you would dump things like `ncol`, `nrow`, `head`, `tail` and all these convenience utilities that people from `R` or `Pandas` expect to find. Instead of endless discussions, you could point people to the package, while “not recommending it”.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [May 12, 2021, 4:09am UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/37 "2021-05-12T04:09:03Z")

</div>

> [@ptoche](#):
>
> Have you considered making a small package `DataFramesExtra`

No. Have you?

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [May 12, 2021, 6:01am UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/38 "2021-05-12T06:01:49Z")

</div>

This was a comment intended for Bogumił.

![a](https://global.discourse-cdn.com/julialang/original/3X/e/7/e78f6a4b5a2b30ae95e8a0e3d9e35d2344f467ff.png)

---

<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:** [May 12, 2021, 7:55am UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/39 "2021-05-12T07:55:24Z")

</div>

> [@ptoche](#):
>
> Instead of endless discussions

In fact I stopped seeing these discussions for many months now. However, incidentally, this week on my blogpost I planned to comment why we support `nrow` and `ncol` but not `head` and `tail`. The core of the issue is:

- number of verbs the user has to learn
- how likely a name clash is when we introduce some exported name
- is there already a name in Julia Base that does a similar thing

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [May 12, 2021, 10:03am UTC](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988/40 "2021-05-12T10:03:01Z")

</div>

I completely understand and just as Michael said, it’s just a matter of getting used to it. `DataFrames` is a fantastic package.

Personally I use R, Python, Julia, Maple, Matlab (and a few more) on and off as the need arises, have become skilled in none of them, and find it difficult to remember right away whether it’s `head(df)`, `df.head`, `first(df)`, or whatever.

The first step for me is usually:

```
julia> ?head

```

When that fails I google for “Julia DataFrames head”. This is how I got to this thread and no doubt will visit again in the future.

Might be useful to have `?head` return something like “Couldn’t find `head`. Perhaps you are looking for `first`” rather than the current “Couldn’t find `head`. Perhaps you meant `read`, …”

[Previous page](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988.md?page=1)

[Next page](https://discourse.julialang.org/t/i-might-have-missed-this-but-why-is-head-df-abstractdataframe-deprecated/27988.md?page=3)
