# Create a dataframe with two titles

**URL:** <https://discourse.julialang.org/t/create-a-dataframe-with-two-titles/19844>\
**Category:** General Usage\
**Created:** [January 20, 2019, 4:03pm UTC](https://discourse.julialang.org/t/create-a-dataframe-with-two-titles/19844 "2019-01-20T16:03:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [January 20, 2019, 4:03pm UTC](https://discourse.julialang.org/t/create-a-dataframe-with-two-titles/19844/1 "2019-01-20T16:03:33Z")

</div>

Julia DataFrames.jl seems like a really great way to manipulate data in a tabular form. [https://juliadata.github.io/DataFrames.jl/stable/man/getting\_started.html](https://juliadata.github.io/DataFrames.jl/stable/man/getting_started.html) I was just wondering, is there a simple way to create a data frame with more than one titles? Or put some signature in the corner where the phrase “row” is sitting (see the following)?

```julia
julia> using DataFrames

julia> df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"])
4×2 DataFrame
│ Row │ A │ B │
│ │ Int64 │ String │
├─────┼───────┼────────┤
│ 1 │ 1 │ M │
│ 2 │ 2 │ F │
│ 3 │ 3 │ F │
│ 4 │ 4 │ M │

```

EDIT: yes. I should have made this clear. The following might be a good context.  
Suppose we have a process which starts at a certain time t. Then, this time t is a parameter / signature which only belongs to this process. And in the columns of this data frame, we have other parameters / characteristics. If it’s a table, then the starting time t can be manually put in the title part. For data frames, maybe it can not be done? Any comments are greatly appreciated.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 20, 2019, 10:12pm UTC](https://discourse.julialang.org/t/create-a-dataframe-with-two-titles/19844/2 "2019-01-20T22:12:17Z")

</div>

Can you give an example of what you want the output to look like? WHat is the “title” of a DataFrame?

---

<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 21, 2019, 7:16am UTC](https://discourse.julialang.org/t/create-a-dataframe-with-two-titles/19844/3 "2019-01-21T07:16:14Z")

</div>

> [@bsnyh](#):
>
> I was just wondering, is there a simple way to create a data frame with more than one titles?

It is not clear what you are referring to — `DataFrame`s have no “title”.

> [@bsnyh](#):
>
> Or put some signature in the corner where the phrase “row” is sitting (see the following)?

The `Row` in the table comes from the `Base.show` method, and is hardcoded. Making it customizable per dataframe would need a minor redesign of the library.

It is unclear what you need this for — perhaps you could provide some context.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [January 21, 2019, 8:41am UTC](https://discourse.julialang.org/t/create-a-dataframe-with-two-titles/19844/4 "2019-01-21T08:41:33Z")

</div>

@Tamas_Papp, I have edited the original post.

---

<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 21, 2019, 8:44am UTC](https://discourse.julialang.org/t/create-a-dataframe-with-two-titles/19844/5 "2019-01-21T08:44:54Z")

</div>

It looks like you want metadata:

> [@How to add metadata info to a DataFrame?](https://discourse.julialang.org/t/how-to-add-metadata-info-to-a-dataframe/11168):
>
> Storing both data and metadata in the same object or container is a very common approach in many research fields, and it has proven to be very successful in (for instance) astronomy where a few standards had been officialized and are now commonly used (e.g. [FITS](https://en.wikipedia.org/wiki/FITS) and [VOTable](http://www.ivoa.net/documents/VOTable/20130920/REC-VOTable-1.3-20130920.html)). In Julia a common way to represent tabular data is by means of a DataFrame, and I (as an astronomer) would like to associate metadata informations to such object, both to the table as a whole and to individual columns. Bu…

TL;DR: AFAIK there are several experiments, but no solution one can call standard at the moment.

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [January 21, 2019, 10:36am UTC](https://discourse.julialang.org/t/create-a-dataframe-with-two-titles/19844/6 "2019-01-21T10:36:46Z")

</div>

With [ReusePatterns.jl](https://github.com/gcalderone/ReusePatterns.jl) you can build a wrapper around a `DataFrame` object:

```julia
using DataFrames, ReusePatterns

mutable struct CustomDataFrame <: AbstractDataFrame
    p::DataFrame
    customtitle::String
    CustomDataFrame(args...; kw...) = new(DataFrame(args...; kw...), "")
    CustomDataFrame(df::DataFrame) = new(df, "")
end
@forward((CustomDataFrame, :p), DataFrame) # <-- reuse all existing methods

# Custom methods:
settitle!(df::CustomDataFrame, s::AbstractString) = setfield!(df, :customtitle, s)
Base.show(df::CustomDataFrame; kw...) = show(stdout, df; kw...)
function Base.show(io::IO, df::CustomDataFrame; kw...)
    println(io, "TITLE: ", getfield(df, :customtitle))
    show(io, getfield(df, :p); kw...)
end

```

and use it as follows:

```julia
df = CustomDataFrame(A = 1:4, B = ["M", "F", "F", "M"])
settitle!(df, "My custom title!")
show(df)

```

The output is:

```julia
julia> show(df)
TITLE: My custom title!
4×2 DataFrame
│ Row │ A │ B │
│ │ Int64 │ String │
├─────┼───────┼────────┤
│ 1 │ 1 │ M │
│ 2 │ 2 │ F │
│ 3 │ 3 │ F │
│ 4 │ 4 │ M │

```
